#define SETTING_MEMORY_TEMP_FILE_PATH "/tmp/email_tmp_file"
-#define EMF_STORAGE_CHANGE_NOTI "User.Email.StorageChange"
-#define EMF_NETOWRK_CHANGE_NOTI "User.Email.NetworkStatus"
+#define EMAIL_STORAGE_CHANGE_NOTI "User.Email.StorageChange"
+#define EMAIL_NETOWRK_CHANGE_NOTI "User.Email.NetworkStatus"
+#define EMAIL_RESPONSE_TO_API_NOTI "User.Email.ResponseToAPI"
#define CONTENT_DATA "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset="
#define CONTENT_TYPE_DATA "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
#undef close
+#define ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL 256
+#define EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL 128
+#define SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL 1027
+#define FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL 256
+
#define ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL 50
#define RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 50
#define EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL 128
#define THREAD_TOPIC_LEN_IN_MAIL_TBL 256
#define TEXT_1_LEN_IN_MAIL_TBL 256
#define TEXT_2_LEN_IN_MAIL_TBL 256
+#define MIME_ENTITY_LEN_IN_MAIL_TBL 256
#define DATETIME_LEN_IN_MAIL_TBL 128
#define MESSAGE_ID_LEN_IN_MAIL_TBL 256
#define FROM_CONTACT_NAME_LEN_IN_MAIL_TBL 3999
#define GLOBAL_OBJECT_ID_LEN_IN_MAIL_MEETING_TBL 512
#define STANDARD_NAME_LEN_IN_MAIL_MEETING_TBL 32
#define DAYLIGHT_NAME_LEN_IN_MAIL_MEETING_TBL 32
-#define PREVIEWBODY_LEN_IN_MAIL_TBL 512
+#define PREVIEWBODY_LEN_IN_MAIL_TBL 512
+#define CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL 256
/* this define is used for query to change data (delete, insert, update) */
#define EMSTORAGE_START_WRITE_TRANSACTION(transaction_flag, error_code) \
{\
if (emstorage_commit_transaction(NULL, NULL, NULL) == false)\
{\
- error_code = EMF_ERROR_DB_FAILURE;\
+ error_code = EMAIL_ERROR_DB_FAILURE;\
result_code = false;\
}\
}\
else\
{\
if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)\
- error_code = EMF_ERROR_DB_FAILURE;\
+ error_code = EMAIL_ERROR_DB_FAILURE;\
}\
_unlockshm_mutex(&mapped_for_db_lock);\
}
static pthread_mutex_t _dbus_noti_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t _db_handle_lock = PTHREAD_MUTEX_INITIALIZER;
+static int _get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type);
+
#define _MULTIPLE_DB_HANDLE
#ifdef _MULTIPLE_DB_HANDLE
int emstorage_set_db_handle(sqlite3 *db_handle)
{
EM_DEBUG_FUNC_BEGIN();
- int i, error_code = EMF_ERROR_MAX_EXCEEDED;
+ int i, error_code = EMAIL_ERROR_MAX_EXCEEDED;
pthread_t current_thread_id = THREAD_SELF();
ENTER_CRITICAL_SECTION(_db_handle_lock);
_db_handle_list[i].thread_id = current_thread_id;
_db_handle_list[i].db_handle = db_handle;
EM_DEBUG_LOG("current_thread_id [%d], index [%d]", current_thread_id, i);
- error_code = EMF_ERROR_NONE;
+ error_code = EMAIL_ERROR_NONE;
break;
}
}
LEAVE_CRITICAL_SECTION(_db_handle_lock);
- if (error_code == EMF_ERROR_MAX_EXCEEDED)
+ if (error_code == EMAIL_ERROR_MAX_EXCEEDED)
EM_DEBUG_EXCEPTION("Exceeded the limitation of db client. Can't find empty slot in _db_handle_list.");
EM_DEBUG_FUNC_END("error_code [%d]", error_code);
int emstorage_remove_db_handle()
{
EM_DEBUG_FUNC_BEGIN();
- int i, error_code = EMF_ERROR_MAX_EXCEEDED;
+ int i, error_code = EMAIL_ERROR_MAX_EXCEEDED;
ENTER_CRITICAL_SECTION(_db_handle_lock);
for (i = 0; i < MAX_DB_CLIENT; i++)
{
_db_handle_list[i].thread_id = 0;
_db_handle_list[i].db_handle = NULL;
EM_DEBUG_LOG("index [%d]", i);
- error_code = EMF_ERROR_NONE;
+ error_code = EMAIL_ERROR_NONE;
break;
}
}
LEAVE_CRITICAL_SECTION(_db_handle_lock);
- if (error_code == EMF_ERROR_MAX_EXCEEDED)
+ if (error_code == EMAIL_ERROR_MAX_EXCEEDED)
EM_DEBUG_EXCEPTION("Can't find proper thread_id");
EM_DEBUG_FUNC_END("error_code [%d]", error_code);
LEAVE_CRITICAL_SECTION(_db_handle_lock)
EM_DEBUG_FUNC_END();
- return EMF_ERROR_NONE;
+ return EMAIL_ERROR_NONE;
}
sqlite3 *emstorage_get_db_connection()
EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
if(!shm_file_name) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
int fd = shm_open(shm_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); /* note: permission is not working */
EM_DEBUG_LOG("** Create SHM FILE **");
if (ftruncate(fd, sizeof(mmapped_t)) != 0) {
EM_DEBUG_EXCEPTION("ftruncate failed: %s", strerror(errno));
- return EMF_ERROR_SYSTEM_FAILURE;
+ return EMAIL_ERROR_SYSTEM_FAILURE;
}
mmapped_t *m = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (m == MAP_FAILED) {
EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno));
- return EMF_ERROR_SYSTEM_FAILURE;
+ return EMAIL_ERROR_SYSTEM_FAILURE;
}
m->data = 0;
pthread_mutexattr_t mattr;
pthread_mutexattr_init(&mattr);
pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
- pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+ pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP);
pthread_mutex_init(&(m->mutex), &mattr);
pthread_mutexattr_destroy(&mattr);
}
else {
EM_DEBUG_EXCEPTION("shm_open failed: %s", strerror(errno));
- return EMF_ERROR_SYSTEM_FAILURE;
+ return EMAIL_ERROR_SYSTEM_FAILURE;
}
close(fd);
EM_DEBUG_FUNC_END();
- return EMF_ERROR_NONE;
+ return EMAIL_ERROR_NONE;
}
int emstorage_shm_file_destroy(const char *shm_file_name)
{
EM_DEBUG_FUNC_BEGIN("shm_file_name [%p]", shm_file_name);
if(!shm_file_name) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
if (shm_unlink(shm_file_name) != 0)
EM_DEBUG_EXCEPTION("shm_unlink failed: %s", strerror(errno));
EM_DEBUG_FUNC_END();
- return EMF_ERROR_NONE;
+ return EMAIL_ERROR_NONE;
}
static int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_t **param_mapped)
EM_DEBUG_FUNC_BEGIN("shm_file_name [%p] param_shm_fd [%p], param_mapped [%p]", shm_file_name, param_shm_fd, param_mapped);
if(!shm_file_name || !param_shm_fd || !param_mapped) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
if (!(*param_mapped)) {
*param_shm_fd = shm_open(shm_file_name, O_RDWR, 0);
if ((*param_shm_fd) == -1) {
EM_DEBUG_EXCEPTION("FAIL: shm_open(): %s", strerror(errno));
- return EMF_ERROR_SYSTEM_FAILURE;
+ return EMAIL_ERROR_SYSTEM_FAILURE;
}
}
mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0);
if (tmp == MAP_FAILED) {
EM_DEBUG_EXCEPTION("mmap failed: %s", strerror(errno));
- return EMF_ERROR_SYSTEM_FAILURE;
+ return EMAIL_ERROR_SYSTEM_FAILURE;
}
*param_mapped = tmp;
}
EM_DEBUG_FUNC_END();
- return EMF_ERROR_NONE;
+ return EMAIL_ERROR_NONE;
}
static int _timedlock_shm_mutex(mmapped_t **param_mapped, int sec)
EM_DEBUG_FUNC_BEGIN("param_mapped [%p], sec [%d]", param_mapped, sec);
if(!param_mapped) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
struct timespec abs_time;
int err = pthread_mutex_timedlock(&((*param_mapped)->mutex), &abs_time);
if (err == EOWNERDEAD) {
- err = pthread_mutex_consistent_np(&((*param_mapped)->mutex));
+ err = pthread_mutex_consistent(&((*param_mapped)->mutex));
EM_DEBUG_EXCEPTION("Previous owner is dead with lock. Fix mutex : %s", EM_STRERROR(err));
}
else if (err != 0) {
}
EM_DEBUG_FUNC_END();
- return EMF_ERROR_NONE;
+ return EMAIL_ERROR_NONE;
}
void _unlockshm_mutex(mmapped_t **param_mapped)
static int _get_password_file_name(int account_id, char *recv_password_file_name, char *send_password_file_name);
static int _read_password_from_secure_storage(char *file_name, char **password);
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+static int _get_cert_password_file_name(int index, char *cert_password_file_name);
+#endif
typedef struct {
const char *object_name;
unsigned int data_flag;
-} emf_db_object_t;
+} email_db_object_t;
-static const emf_db_object_t _g_db_tables[] =
+static const email_db_object_t _g_db_tables[] =
{
{ "mail_read_mail_uid_tbl", 1},
{ "mail_tbl", 1},
{ NULL, 0},
};
-static const emf_db_object_t _g_db_indexes[] =
+static const email_db_object_t _g_db_indexes[] =
{
{ "mail_read_mail_uid_idx1", 1},
{ "mail_idx1", 1},
#ifdef __FEATURE_LOCAL_ACTIVITY__
CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL,
#endif
+ CREATE_TABLE_MAIL_CERTIFICATE_TBL,
CREATE_TABLE_MAX,
};
FLAG_IDX_IN_MAIL_ACTIVITY_TBL,
};
-
-enum
+enum
{
- ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL = 0,
- ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
- RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL,
- RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
- EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
- USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
- PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL,
- RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL,
- PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL,
- USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL,
- SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL,
- DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL,
- REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
- RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL,
- ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL,
- KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL,
- FLAG1_IDX_IN_MAIL_ACCOUNT_TBL,
- FLAG2_IDX_IN_MAIL_ACCOUNT_TBL,
- POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL,
- APOP_IDX_IN_MAIL_ACCOUNT_TBL,
- LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL,
- PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL,
- TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL,
- CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL,
- PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL,
- KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL,
- REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL,
- REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL,
- DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL,
- BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL,
- BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL,
- DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL,
- REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL,
- FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL,
- ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL,
- ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL,
- SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL,
- ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL,
- MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL,
- INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL,
- SYNC_STATUS_IDX_IN_MAIL_ACCOUNT_TBL,
+ CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL = 0,
+ ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL,
+ ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL,
+ ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL,
+ EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL,
+ EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL,
+ EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL,
+ ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL,
+ EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL,
+ SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL,
+ FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL,
};
enum
enum
{
ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL = 0,
- LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL,
+ LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL,
S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL,
TYPE_IDX_IN_MAIL_RULE_TBL,
VALUE_IDX_IN_MAIL_RULE_TBL,
ACTION_TYPE_IDX_IN_MAIL_RULE_TBL,
- DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL,
+ TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL,
FLAG1_IDX_IN_MAIL_RULE_TBL,
FLAG2_IDX_IN_MAIL_RULE_TBL,
};
BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL,
FILE_PATH_PLAIN_IDX_IN_MAIL_TBL,
FILE_PATH_HTML_IDX_IN_MAIL_TBL,
+ FILE_PATH_MIME_ENTITY_IDX_IN_MAIL_TBL,
MAIL_SIZE_IDX_IN_MAIL_TBL,
FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL,
FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL,
THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL,
PREVIEW_TEXT_IDX_IN_MAIL_TBL,
MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL,
- FIELD_COUNT_OF_EMF_MAIL_TBL, /* End of mail_tbl */
+ MESSAGE_CLASS_IDX_IN_MAIL_TBL,
+ DIGEST_TYPE_IDX_IN_MAIL_TBL,
+ SMIME_TYPE_IDX_IN_MAIL_TBL,
+ FIELD_COUNT_OF_MAIL_TBL, /* End of mail_tbl */
};
enum
ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL,
MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
- MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL,
+ MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL,
ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL,
ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL,
ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL,
static char *g_test_query[] = {
/* 1. select mail_account_tbl */
"SELECT"
- " account_bind_type, "
" account_name, "
- " receiving_server_type, "
- " receiving_server_addr, "
- " email_addr, "
- " user_name, "
- " password, "
+ " incoming_server_type, "
+ " incoming_server_address, "
+ " user_email_address, "
+ " incoming_server_user_name, "
+ " incoming_server_password, "
" retrieval_mode, "
- " port_num, "
- " use_security, "
- " sending_server_type, "
- " sending_server_addr, "
- " sending_port_num, "
- " sending_auth, "
- " sending_security, "
- " sending_user, "
- " sending_password, "
+ " incoming_server_port_number, "
+ " incoming_server_secure_connection, "
+ " outgoing_server_type, "
+ " outgoing_server_address, "
+ " outgoing_server_port_number, "
+ " outgoing_server_need_authentication, "
+ " outgoing_server_secure_connection, "
+ " outgoing_server_user_name, "
+ " outgoing_server_password, "
" display_name, "
" reply_to_addr, "
" return_addr, "
" account_id, "
- " keep_on_server, "
+ " keep_mails_on_pop_server_after_download, "
" flag1, "
" flag2, "
" pop_before_smtp, "
- " apop"
+ " incoming_server_requires_apop"
", logo_icon_path, "
- " preset_account, "
- " target_storage, "
+ " is_preset_account, "
" check_interval, "
" priority, "
" keep_local_copy, "
" add_signature, "
" signature"
", add_my_address_to_bcc"
- ", my_account_id "
+ ", account_svc_id "
", index_color "
", sync_status "
+ ", sync_disabled "
+ ", smime_type"
+ ", certificate_path"
+ ", cipher_type"
+ ", digest_type"
" FROM mail_account_tbl",
/* 2. select mail_box_tbl */
"SELECT "
" total_mail_count_on_server, "
" has_archived_mails, "
" mail_slot_size "
+ " last_sync_time "
" FROM mail_box_tbl ",
/* 3. select mail_read_mail_uid_tbl */
"SELECT "
" account_id, "
- " local_mbox, "
+ " mailbox_id, "
" local_uid, "
" mailbox_name, "
" s_uid, "
" type, "
" value, "
" action_type, "
- " dest_mailbox, "
+ " target_mailbox_id, "
" flag1, "
" flag2 "
" FROM mail_rule_tbl ",
" body_download_status, "
" file_path_plain, "
" file_path_html, "
+ " file_path_mime_entity, "
" mail_size, "
" flags_seen_field ,"
" flags_deleted_field ,"
" inline_content_count, "
" thread_id, "
" thread_item_count, "
- " preview_text"
+ " preview_text, "
" meeting_request_status, "
+ " message_class, "
+ " digest_type, "
+ " smime_type "
" FROM mail_tbl",
/* 6. select mail_attachment_tbl */
"SELECT "
" attachment_size, "
" mail_id, "
" account_id, "
- " mailbox_name, "
+ " mailbox_id, "
" attachment_save_status, "
" attachment_drm_type, "
" attachment_drm_method, "
" server_mail_id, "
" activity_id, "
" activity_type, "
+ " mailbox_id, "
" mailbox_name "
" FROM mail_partial_body_activity_tbl ",
#endif
"SELECT "
" mail_id, "
" account_id, "
- " mailbox_name, "
+ " mailbox_id, "
" meeting_response, "
" start_time, "
" end_time, "
/* ----------- Notification Changes ----------- */
typedef enum
{
- _NOTI_TYPE_STORAGE,
- _NOTI_TYPE_NETWORK
+ _NOTI_TYPE_STORAGE = 0,
+ _NOTI_TYPE_NETWORK = 1,
+ _NOTI_TYPE_RESPONSE_TO_API = 2,
} enotitype_t;
}
if (notiType == _NOTI_TYPE_STORAGE) {
- signal = dbus_message_new_signal("/User/Email/StorageChange", EMF_STORAGE_CHANGE_NOTI, "email");
+ signal = dbus_message_new_signal("/User/Email/StorageChange", EMAIL_STORAGE_CHANGE_NOTI, "email");
if (signal == NULL) {
EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
}
else if (notiType == _NOTI_TYPE_NETWORK) {
- signal = dbus_message_new_signal("/User/Email/NetworkStatus", EMF_NETOWRK_CHANGE_NOTI, "email");
+ signal = dbus_message_new_signal("/User/Email/NetworkStatus", EMAIL_NETOWRK_CHANGE_NOTI, "email");
if (signal == NULL) {
EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
dbus_message_append_args(signal, DBUS_TYPE_INT32, &data4, DBUS_TYPE_INVALID);
}
+ else if (notiType == _NOTI_TYPE_RESPONSE_TO_API) {
+ signal = dbus_message_new_signal("/User/Email/ResponseToAPI", EMAIL_RESPONSE_TO_API_NOTI, "email");
+
+ if (signal == NULL) {
+ EM_DEBUG_EXCEPTION("dbus_message_new_signal is failed");
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("/User/Email/ResponseToAPI Signal is created by dbus_message_new_signal");
+
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &subType, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data1, DBUS_TYPE_INVALID);
+ dbus_message_append_args(signal, DBUS_TYPE_INT32, &data2, DBUS_TYPE_INVALID);
+ }
else {
EM_DEBUG_EXCEPTION("Wrong notification type [%d]", notiType);
- error = EMF_ERROR_IPC_CRASH;
+ error = EMAIL_ERROR_IPC_CRASH;
goto FINISH_OFF;
}
}
/* EM_DEBUG_LOG("Before dbus_connection_flush"); */
-/* dbus_connection_flush(connection); */
+/* dbus_connection_flush(connection); */
/* EM_DEBUG_LOG("After dbus_connection_flush"); */
ret = true;
}
-INTERNAL_FUNC int emstorage_notify_storage_event(emf_noti_on_storage_event transaction_type, int data1, int data2 , char *data3, int data4)
+INTERNAL_FUNC int emstorage_notify_storage_event(email_noti_on_storage_event transaction_type, int data1, int data2 , char *data3, int data4)
{
EM_DEBUG_FUNC_BEGIN("transaction_type[%d], data1[%d], data2[%d], data3[%p], data4[%d]", transaction_type, data1, data2, data3, data4);
return emstorage_send_noti(_NOTI_TYPE_STORAGE, (int)transaction_type, data1, data2, data3, data4);
}
-INTERNAL_FUNC int emstorage_notify_network_event(emf_noti_on_network_event status_type, int data1, char *data2, int data3, int data4)
+INTERNAL_FUNC int emstorage_notify_network_event(email_noti_on_network_event status_type, int data1, char *data2, int data3, int data4)
{
EM_DEBUG_FUNC_BEGIN("status_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", status_type, data1, data2, data3, data4);
return emstorage_send_noti(_NOTI_TYPE_NETWORK, (int)status_type, data1, data3, data2, data4);
}
+INTERNAL_FUNC int emstorage_notify_response_to_api(email_event_type_t event_type, int data1, int data2)
+{
+ EM_DEBUG_FUNC_BEGIN("event_type[%d], data1[%d], data2[%p], data3[%d], data4[%d]", event_type, data1, data2);
+ return emstorage_send_noti(_NOTI_TYPE_RESPONSE_TO_API, (int)event_type, data1, data2, NULL, 0);
+}
+
/* ----------- Notification Changes End----------- */
static int _get_table_field_data_char(char **table, char *buf, int index)
{
return false;
}
+static void _get_stmt_field_data_blob(DB_STMT hStmt, void **buf, int index)
+{
+ if ((hStmt < 0) || (buf == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("hStmt[%d], buf[%p], index[%d]", hStmt, buf, index);
+ return;
+ }
+
+ int sLen = 0;
+ sLen = sqlite3_column_bytes(hStmt, index);
+
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("_get_stmt_field_data_blob sqlite3_column_bytes sLen[%d]", sLen);
+#endif
+
+ if (sLen > 0) {
+ *buf = (char *) em_malloc(sLen);
+ memcpy(*buf, (void *)sqlite3_column_blob(hStmt, index), sLen);
+ }
+ else
+ *buf = NULL;
+
+}
+
static int _get_stmt_field_data_string_without_allocation(DB_STMT hStmt, char *buf, int buffer_size, int ucs2, int index)
{
if ((hStmt < 0) || (buf == NULL) || (index < 0)) {
return true;
}
+
+static int _bind_stmt_field_data_blob(DB_STMT hStmt, int index, void *blob, int blob_size)
+{
+ if ((hStmt == NULL) || (index < 0)) {
+ EM_DEBUG_EXCEPTION("index[%d], blob_size[%d]", index, blob_size);
+ return false;
+ }
+
+#ifdef _PRINT_STORAGE_LOG_
+ EM_DEBUG_LOG("hStmt = %p, index = %d, blob_size = %d, blob = [%p]", hStmt, index, blob_size, blob);
+#endif
+
+ int ret = 0;
+ if (blob_size>0)
+ ret = sqlite3_bind_blob(hStmt, index+1, blob, blob_size, SQLITE_STATIC);
+ else
+ ret = sqlite3_bind_null(hStmt, index+1);
+
+ if (ret != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_bind_blob fail [%d]", ret);
+ return false;
+ }
+ return true;
+}
+
+
static int _delete_temp_file(const char *path)
{
EM_DEBUG_FUNC_BEGIN("path[%p]", path);
EM_DEBUG_FUNC_BEGIN();
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
emstorage_db_close(&error);
{
EM_DEBUG_FUNC_BEGIN();
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
mkdir(EMAILPATH, DIRECTORY_PERMISSION);
mkdir(DATA_PATH, DIRECTORY_PERMISSION);
g_transaction = false;
- if (!emstorage_create_table(EMF_CREATE_DB_NORMAL, &error)) {
+ if (!emstorage_create_table(EMAIL_CREATE_DB_NORMAL, &error)) {
EM_DEBUG_EXCEPTION(" emstorage_create_table failed - %d", error);
goto FINISH_OFF;
}
/* pData : a parameter which is registered when busy handler is registerd */
/* count : retry count */
-#define EMF_STORAGE_MAX_RETRY_COUNT 20
+#define EMAIL_STORAGE_MAX_RETRY_COUNT 20
static int _callback_sqlite_busy_handler(void *pData, int count)
{
EM_DEBUG_LOG("Busy Handler Called!!: [%d]", count);
usleep(200000); /* sleep time when SQLITE_LOCK */
/* retry will be stopped if busy handler return 0 */
- return EMF_STORAGE_MAX_RETRY_COUNT - count;
+ return EMAIL_STORAGE_MAX_RETRY_COUNT - count;
}
static int _delete_all_files_and_directories(int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int ret = false;
if (!emstorage_delete_file(EMAIL_SERVICE_DB_FILE_PATH, &error)) {
- if (error != EMF_ERROR_FILE_NOT_FOUND) {
+ if (error != EMAIL_ERROR_FILE_NOT_FOUND) {
EM_DEBUG_EXCEPTION("remove failed - %s", EMAIL_SERVICE_DB_FILE_PATH);
goto FINISH_OFF;
}
{
EM_DEBUG_FUNC_BEGIN();
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int ret = false;
/* Delete all files and directories */
{
EM_DEBUG_FUNC_BEGIN();
int rc = 0;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int ret = false;
EM_DEBUG_LOG("*sqlite_handle[%p]", *sqlite_handle);
EMSTORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc);
if (SQLITE_OK != rc) {
EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
db_util_close(*sqlite_handle);
*sqlite_handle = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(db_util_open(EMAIL_SERVICE_DB_FILE_PATH, sqlite_handle, DB_UTIL_REGISTER_HOOK_METHOD), rc);
if (SQLITE_OK != rc) {
EM_DEBUG_EXCEPTION("db_util_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
db_util_close(*sqlite_handle);
*sqlite_handle = NULL;
}
rc = sqlite3_busy_handler(*sqlite_handle, _callback_sqlite_busy_handler, NULL); /* Busy Handler registration, NULL is a parameter which will be passed to handler */
if (SQLITE_OK != rc) {
EM_DEBUG_EXCEPTION("sqlite3_busy_handler fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle));
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
db_util_close(*sqlite_handle);
*sqlite_handle = NULL;
goto FINISH_OFF;
sqlite3 *_db_handle = NULL;
#endif
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
_initialize_shm_mutex(SHM_FILE_FOR_DB_LOCK, &shm_fd_for_db_lock, &mapped_for_db_lock);
sqlite3 *_db_handle = emstorage_get_db_handle();
#endif
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int ret = false;
DELETE_CRITICAL_SECTION(_transactionBeginLock);
if (ret != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" db_util_close fail - %d", ret);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
ret = false;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN();
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int retValue;
{
EM_DEBUG_FUNC_BEGIN();
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc = -1, ret = false;
char sql_query_string[QUERY_SIZE] = {0, };
char *create_table_query[] =
/* 1. create mail_account_tbl */
"CREATE TABLE mail_account_tbl \n"
"(\n"
- " account_bind_type INTEGER \n"
- ", account_name VARCHAR(51) \n"
- ", receiving_server_type INTEGER \n"
- ", receiving_server_addr VARCHAR(51) \n"
- ", email_addr VARCHAR(129) \n"
- ", user_name VARCHAR(51) \n"
- ", password VARCHAR(51) \n"
- ", retrieval_mode INTEGER \n"
- ", port_num INTEGER \n"
- ", use_security INTEGER \n"
- ", sending_server_type INTEGER \n"
- ", sending_server_addr VARCHAR(51) \n"
- ", sending_port_num INTEGER \n"
- ", sending_auth INTEGER \n"
- ", sending_security INTEGER \n"
- ", sending_user VARCHAR(51) \n"
- ", sending_password VARCHAR(51) \n"
- ", display_name VARCHAR(31) \n"
- ", reply_to_addr VARCHAR(129) \n"
- ", return_addr VARCHAR(129) \n"
- ", account_id INTEGER PRIMARY KEY \n"
- ", keep_on_server INTEGER \n"
- ", flag1 INTEGER \n"
- ", flag2 INTEGER \n"
- ", pop_before_smtp INTEGER \n" /* POP before SMTP authentication */
- ", apop INTEGER \n" /* APOP authentication */
- ", logo_icon_path VARCHAR(256) \n" /* Receiving Option : Account logo icon */
- ", preset_account INTEGER \n" /* Receiving Option : Preset account or not */
- ", target_storage INTEGER \n" /* Receiving Option : Specifies the targetStorage. 0 is phone, 1 is MMC */
- ", check_interval INTEGER \n" /* Receiving Option : Specifies the check interval. Unit is minute */
- ", priority INTEGER \n" /* Sending Option : Specifies the prority. 1=high 3=normal 5=low */
- ", keep_local_copy INTEGER \n" /* Sending Option : */
- ", req_delivery_receipt INTEGER \n" /* Sending Option : */
- ", req_read_receipt INTEGER \n" /* Sending Option : */
- ", download_limit INTEGER \n" /* Sending Option : */
- ", block_address INTEGER \n" /* Sending Option : */
- ", block_subject INTEGER \n" /* Sending Option : */
- ", display_name_from VARCHAR(256) \n" /* Sending Option : */
- ", reply_with_body INTEGER \n" /* Sending Option : */
- ", forward_with_files INTEGER \n" /* Sending Option : */
- ", add_myname_card INTEGER \n" /* Sending Option : */
- ", add_signature INTEGER \n" /* Sending Option : */
- ", signature VARCHAR(256) \n" /* Sending Option : */
- ", add_my_address_to_bcc INTEGER \n" /* Sending Option : */
- ", my_account_id INTEGER \n" /* My Account Id */
- ", index_color INTEGER \n" /* Index color */
- ", sync_status INTEGER \n" /* Sync Status */
- ");",
+ "account_id INTEGER PRIMARY KEY,\n"
+ "account_name VARCHAR(51),\n"
+ "logo_icon_path VARCHAR(256),\n"
+ "user_data BLOB,\n"
+ "user_data_length INTEGER,\n"
+ "account_svc_id INTEGER,\n"
+ "sync_status INTEGER,\n"
+ "sync_disabled INTEGER,\n"
+ "default_mail_slot_size INTEGER,\n"
+ "user_display_name VARCHAR(31),\n"
+ "user_email_address VARCHAR(129),\n"
+ "reply_to_address VARCHAR(129),\n"
+ "return_address VARCHAR(129),\n"
+ "incoming_server_type INTEGER,\n"
+ "incoming_server_address VARCHAR(51),\n"
+ "incoming_server_port_number INTEGER,\n"
+ "incoming_server_user_name VARCHAR(51),\n"
+ "incoming_server_password VARCHAR(51),\n"
+ "incoming_server_secure_connection INTEGER,\n"
+ "retrieval_mode INTEGER,\n"
+ "keep_mails_on_pop_server_after_download INTEGER,\n"
+ "check_interval INTEGER,\n"
+ "auto_download_size INTEGER,\n"
+ "outgoing_server_type INTEGER,\n"
+ "outgoing_server_address VARCHAR(51),\n"
+ "outgoing_server_port_number INTEGER,\n"
+ "outgoing_server_user_name VARCHAR(51),\n"
+ "outgoing_server_password VARCHAR(51),\n"
+ "outgoing_server_secure_connection INTEGER,\n"
+ "outgoing_server_need_authentication INTEGER,\n"
+ "outgoing_server_use_same_authenticator INTEGER,\n"
+ "priority INTEGER,\n"
+ "keep_local_copy INTEGER,\n"
+ "req_delivery_receipt INTEGER,\n"
+ "req_read_receipt INTEGER,\n"
+ "download_limit INTEGER,\n"
+ "block_address INTEGER,\n"
+ "block_subject INTEGER,\n"
+ "display_name_from VARCHAR(256),\n"
+ "reply_with_body INTEGER,\n"
+ "forward_with_files INTEGER,\n"
+ "add_myname_card INTEGER,\n"
+ "add_signature INTEGER,\n"
+ "signature VARCHAR(256),\n"
+ "add_my_address_to_bcc INTEGER,\n"
+ "pop_before_smtp INTEGER,\n"
+ "incoming_server_requires_apop INTEGER,\n"
+ "smime_type INTEGER,\n"
+ "certificate_path VARCHAR(256),\n"
+ "cipher_type INTEGER,\n"
+ "digest_type INTEGER\n"
+ "); \n ",
/* 2. create mail_box_tbl */
"CREATE TABLE mail_box_tbl \n"
"(\n"
", total_mail_count_on_server INTEGER \n"
", has_archived_mails INTEGER \n"
", mail_slot_size INTEGER \n"
+ ", last_sync_time DATETIME \n"
"); \n ",
/* 3. create mail_read_mail_uid_tbl */
"CREATE TABLE mail_read_mail_uid_tbl \n"
"(\n"
" account_id INTEGER \n"
- ", local_mbox VARCHAR(129) \n"
+ ", mailbox_id VARCHAR(129) \n"
", local_uid INTEGER \n"
", mailbox_name VARCHAR(256) \n"
", s_uid VARCHAR(129) \n"
", type INTEGER \n"
", value VARCHAR(257) \n"
", action_type INTEGER \n"
- ", dest_mailbox VARCHAR(129) \n"
+ ", target_mailbox_id INTEGER \n"
", flag1 INTEGER \n"
", flag2 INTEGER \n"
"); \n ",
", body_download_status INTEGER \n"
", file_path_plain VARCHAR(257) \n"
", file_path_html VARCHAR(257) \n"
+ ", file_path_mime_entity VARCHAR(257) \n"
", mail_size INTEGER \n"
", flags_seen_field BOOLEAN \n"
", flags_deleted_field BOOLEAN \n"
", thread_item_count INTEGER \n"
", preview_text TEXT \n"
", meeting_request_status INTEGER \n"
+ ", message_class INTEGER \n"
+ ", digest_type INTEGER \n"
+ ", smime_type INTEGER \n"
", FOREIGN KEY(account_id) REFERENCES mail_account_tbl(account_id) \n"
"); \n ",
", attachment_size INTEGER \n"
", mail_id INTEGER \n"
", account_id INTEGER \n"
- ", mailbox_name VARCHAR(129) \n"
+ ", mailbox_id INTEGER \n"
", attachment_save_status INTEGER \n"
", attachment_drm_type INTEGER \n"
", attachment_drm_method INTEGER \n"
", server_mail_id INTEGER \n"
", activity_id INTEGER PRIMARY KEY \n"
", activity_type INTEGER \n"
+ ", mailbox_id INTEGER \n"
", mailbox_name VARCHAR(4000) \n"
"); \n ",
#endif
"(\n"
" mail_id INTEGER PRIMARY KEY \n"
", account_id INTEGER \n"
- ", mailbox_name TEXT \n"
+ ", mailbox_id INTEGER \n"
", meeting_response INTEGER \n"
", start_time INTEGER \n"
", end_time INTEGER \n"
", dest_mbox VARCHAR(129) \n"
"); \n ",
#endif
+ "CREATE TABLE mail_certificate_tbl \n"
+ "( \n"
+ " certificate_id INTEGER \n"
+ ", issue_year INTEGER \n"
+ ", issue_month INTEGER \n"
+ ", issue_day INTEGER \n"
+ ", expiration_year INTEGER \n"
+ ", expiration_month INTEGER \n"
+ ", expiration_day INTEGER \n"
+ ", issue_organization_name VARCHAR(256) \n"
+ ", email_address VARCHAR(129) \n"
+ ", subject_str VARCHAR(256) \n"
+ ", filepath VARCHAR(256) \n"
+ ", password VARCHAR(51) \n"
+ "); \n ",
NULL,
};
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_account_tbl unique index */
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_bind_type, account_id)");
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_account_idx1 ON mail_account_tbl (account_id)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_account_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_BOX_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_local_mailbox_tbl unique index */
SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_box_idx1 ON mail_box_tbl (account_id, local_yn, mailbox_name)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_box_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_BOX_TBL], NULL, NULL, NULL);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_BOX_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_read_mail_uid_tbl unique index */
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, local_mbox, local_uid, mailbox_name, s_uid)");
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_read_mail_uid_idx1 ON mail_read_mail_uid_tbl (account_id, mailbox_id, local_uid, mailbox_name, s_uid)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_read_mail_uid_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_RULE_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_rule_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_RULE_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_RULE_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_tbl unique index */
SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_idx1 ON mail_tbl (mail_id, account_id)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_tbl index for date_time */
SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE INDEX mail_idx_date_time ON mail_tbl (date_time)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_tbl index for thread_item_count */
SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE INDEX mail_idx_thread_mail_count ON mail_tbl (thread_item_count)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
/* just one time call */
/* EFTSInitFTSIndex(FTS_EMAIL_IDX); */
} /* mail_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* create mail_attachment_tbl unique index */
SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_attachment_idx1 ON mail_attachment_tbl (mail_id, attachment_id) ");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_attachment_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_rule_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_MEETING_TBL], sizeof(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_meeting_idx1 ON mail_meeting_tbl (mail_id)");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_contact_sync_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL]);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
} /* mail_rule_tbl */
- else if (type == EMF_CREATE_DB_CHECK) {
+ else if (type == EMAIL_CREATE_DB_CHECK) {
rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle)));
}
sqlite3_free_table(result);
#endif /* __FEATURE_LOCAL_ACTIVITY__ */
+ /* create mail_certificate_tbl */
+ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_certificate_tbl';";
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (atoi(result[1]) < 1) {
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG("CREATE TABLE mail_certificate_tbl");
+
+ EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], sizeof(sql_query_string));
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "CREATE UNIQUE INDEX mail_certificate_idx1 ON mail_certificate_tbl (certificate_id)");
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc);
+ } /* mail_contact_sync_tbl */
+ else if (type == EMAIL_CREATE_DB_CHECK) {
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], rc, sqlite3_errmsg(local_db_handle)));
+ }
+ sqlite3_free_table(result);
ret = true;
/* Query series --------------------------------------------------------------*/
-INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, emf_mail_list_item_t** result_mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_query_mail_count(const char *input_conditional_clause, int input_transaction, int *output_total_mail_count, int *output_unseen_mail_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_transaction[%d], output_total_mail_count[%p], output_unseen_mail_count[%p]", input_conditional_clause, input_transaction, output_total_mail_count, output_unseen_mail_count);
+ int rc = -1;
+ int error = EMAIL_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char err_msg[1024];
+ char **result;
+ sqlite3 *local_db_handle = NULL;
+
+ if (!input_conditional_clause || (!output_total_mail_count && !output_unseen_mail_count)) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ memset(&sql_query_string, 0x00, sizeof(sql_query_string));
+ local_db_handle = emstorage_get_db_connection();
+
+ EMSTORAGE_START_READ_TRANSACTION(input_transaction);
+
+ SNPRINTF(sql_query_string, QUERY_SIZE, "SELECT COUNT(*) FROM mail_tbl");
+ EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause);
+
+ if (output_total_mail_count) {
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ _get_stmt_field_data_int(hStmt, output_total_mail_count, 0);
+ }
+
+ if (output_unseen_mail_count) {
+ EM_SAFE_STRCAT(sql_query_string, " AND flags_seen_field = 0 ");
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ *output_unseen_mail_count = atoi(result[1]);
+ sqlite3_free_table(result);
+ }
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_finalize failed [%d] : %s", rc, err_msg);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
+ _DISCONNECT_DB;
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
+
+INTERNAL_FUNC int emstorage_query_mail_id_list(const char *input_conditional_clause, int input_transaction, int **output_mail_id_list, int *output_mail_id_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_conditional_clause [%p], input_transaction [%d], output_mail_id_list [%p], output_mail_id_count [%p]", input_conditional_clause, input_transaction, output_mail_id_list, output_mail_id_count);
+
+ int i = 0;
+ int count = 0;
+ int rc = -1;
+ int cur_query = 0;
+ int col_index;
+ int error = EMAIL_ERROR_NONE;
+ int *result_mail_id_list = NULL;
+ char **result = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ EM_IF_NULL_RETURN_VALUE(input_conditional_clause, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(output_mail_id_list, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(output_mail_id_count, EMAIL_ERROR_INVALID_PARAM);
+
+ EMSTORAGE_START_READ_TRANSACTION(input_transaction);
+
+ /* Composing query */
+ SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT mail_id FROM mail_tbl ");
+ EM_SAFE_STRCAT(sql_query_string, (char*)input_conditional_clause);
+
+ EM_DEBUG_LOG("query[%s].", sql_query_string);
+
+ /* Performing query */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ col_index = 1;
+
+ /* to get mail list */
+ if (count == 0) {
+ EM_DEBUG_EXCEPTION("No mail found...");
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("There are [%d] mails.", count);
+
+ if (!(result_mail_id_list = (int*)em_malloc(sizeof(int) * count))) {
+ EM_DEBUG_EXCEPTION("malloc for result_mail_id_list failed...");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG(">>>> DATA ASSIGN START >> ");
+
+ for (i = 0; i < count; i++)
+ _get_table_field_data_int(result, result_mail_id_list + i, col_index++);
+
+ EM_DEBUG_LOG(">>>> DATA ASSIGN END [count : %d] >> ", count);
+
+ *output_mail_id_list = result_mail_id_list;
+ *output_mail_id_count = count;
+
+FINISH_OFF:
+
+ if(result)
+ sqlite3_free_table(result);
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
+ _DISCONNECT_DB;
+
+ if(error != EMAIL_ERROR_NONE)
+ EM_SAFE_FREE(result_mail_id_list);
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
+
+INTERNAL_FUNC int emstorage_query_mail_list(const char *conditional_clause, int transaction, email_mail_list_item_t** result_mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(emstorage_query_mail_list_func);
int i = 0, count = 0, rc = -1, to_get_count = (result_mail_list)?0:1;
int local_inline_content_count = 0, local_attachment_count = 0;
int cur_query = 0, base_count = 0, col_index;
- int ret = false, error = EMF_ERROR_NONE;
+ int ret = false, error = EMAIL_ERROR_NONE;
char *date_time_string = NULL;
char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
- char *field_list = "mail_id, account_id, mailbox_name, full_address_from, email_address_sender, full_address_to, subject, body_download_status, flags_seen_field, flags_deleted_field, flags_flagged_field, flags_answered_field, flags_recent_field, flags_draft_field, flags_forwarded_field, DRM_status, priority, save_status, lock_status, attachment_count, inline_content_count, date_time, preview_text, thread_id, thread_item_count, meeting_request_status ";
- emf_mail_list_item_t *mail_list_item_from_tbl = NULL;
+ char *field_list = "mail_id, account_id, mailbox_id, full_address_from, email_address_sender, full_address_to, subject, body_download_status, flags_seen_field, flags_deleted_field, flags_flagged_field, flags_answered_field, flags_recent_field, flags_draft_field, flags_forwarded_field, DRM_status, priority, save_status, lock_status, attachment_count, inline_content_count, date_time, preview_text, thread_id, thread_item_count, meeting_request_status, message_class, smime_type ";
+ email_mail_list_item_t *mail_list_item_from_tbl = NULL;
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_IF_NULL_RETURN_VALUE(conditional_clause, false);
/* select clause */
if (to_get_count) /* count only */
- cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT count(*) FROM mail_tbl");
+ cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT mail_id FROM mail_tbl");
else /* mail list in plain form */
cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, "SELECT %s FROM mail_tbl ", field_list);
- cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, conditional_clause, 0);
+ /* cur_query += SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, conditional_clause); This code caused some crashes.*/
+ strncat(sql_query_string, conditional_clause, QUERY_SIZE - cur_query);
EM_DEBUG_LOG("emstorage_query_mail_list : query[%s].", sql_query_string);
/* performing query */
EM_PROFILE_BEGIN(emstorage_query_mail_list_performing_query);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_PROFILE_END(emstorage_query_mail_list_performing_query);
EM_DEBUG_LOG("base_count [%d]", base_count);
if (to_get_count) {
- /* to get mail count */
- count = atoi(result[1]);
+ /* to get count */
+ if (!count) {
+ EM_DEBUG_EXCEPTION("No mail found...");
+ ret = false;
+ error= EMAIL_ERROR_MAIL_NOT_FOUND;
+ goto FINISH_OFF;
+ }
EM_DEBUG_LOG("There are [%d] mails.", count);
}
else {
if (!count) {
EM_DEBUG_EXCEPTION("No mail found...");
ret = false;
- error= EMF_ERROR_MAIL_NOT_FOUND;
+ error= EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
EM_DEBUG_LOG("There are [%d] mails.", count);
- if (!(mail_list_item_from_tbl = (emf_mail_list_item_t*)em_malloc(sizeof(emf_mail_list_item_t) * count))) {
+ if (!(mail_list_item_from_tbl = (email_mail_list_item_t*)em_malloc(sizeof(email_mail_list_item_t) * count))) {
EM_DEBUG_EXCEPTION("malloc for mail_list_item_from_tbl failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
for (i = 0; i < count; i++) {
_get_table_field_data_int(result, &(mail_list_item_from_tbl[i].mail_id), col_index++);
_get_table_field_data_int(result, &(mail_list_item_from_tbl[i].account_id), col_index++);
- _get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].mailbox_name, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
+ _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].mailbox_id), col_index++);
_get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].from, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
_get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].from_email_address, MAX_EMAIL_ADDRESS_LENGTH, 1, col_index++);
_get_table_field_data_string_without_allocation(result, mail_list_item_from_tbl[i].recipients, STRING_LENGTH_FOR_DISPLAY, 1, col_index++);
_get_table_field_data_int(result, &(mail_list_item_from_tbl[i].thread_id), col_index++);
_get_table_field_data_int(result, &(mail_list_item_from_tbl[i].thread_item_count), col_index++);
_get_table_field_data_int(result, &(mail_list_item_from_tbl[i].is_meeting_request), col_index++);
+ _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].message_class), col_index++);
+ _get_table_field_data_int(result, &(mail_list_item_from_tbl[i].smime_type), col_index++);
mail_list_item_from_tbl[i].has_attachment = ((local_attachment_count - local_inline_content_count)>0)?1:0;
}
EM_DEBUG_FUNC_BEGIN("conditional_clause[%s], result_mail_tbl[%p], result_count [%p], transaction[%d], err_code[%p]", conditional_clause, result_mail_tbl, result_count, transaction, err_code);
if (!conditional_clause) {
- EM_DEBUG_EXCEPTION("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;
}
- int i, col_index = FIELD_COUNT_OF_EMF_MAIL_TBL, rc, ret = false, count;
- int error = EMF_ERROR_NONE;
+ int i, col_index = FIELD_COUNT_OF_MAIL_TBL, rc, ret = false, count;
+ int error = EMAIL_ERROR_NONE;
char **result = NULL, sql_query_string[QUERY_SIZE] = {0, };
emstorage_mail_tbl_t* p_data_tbl = NULL;
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (!count) {
EM_DEBUG_EXCEPTION("No mail found...");
ret = false;
- error= EMF_ERROR_MAIL_NOT_FOUND;
+ error= EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
EM_DEBUG_LOG("There are [%d] mails.", count);
if (!(p_data_tbl = (emstorage_mail_tbl_t*)em_malloc(sizeof(emstorage_mail_tbl_t) * count))) {
EM_DEBUG_EXCEPTION("malloc for emstorage_mail_tbl_t failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
_get_table_field_data_int (result, &(p_data_tbl[i].body_download_status), col_index++);
_get_table_field_data_string(result, &(p_data_tbl[i].file_path_plain), 0, col_index++);
_get_table_field_data_string(result, &(p_data_tbl[i].file_path_html), 0, col_index++);
+ _get_table_field_data_string(result, &(p_data_tbl[i].file_path_mime_entity), 0, col_index++);
_get_table_field_data_int (result, &(p_data_tbl[i].mail_size), col_index++);
_get_table_field_data_char (result, &(p_data_tbl[i].flags_seen_field), col_index++);
_get_table_field_data_char (result, &(p_data_tbl[i].flags_deleted_field), col_index++);
_get_table_field_data_int (result, &(p_data_tbl[i].thread_item_count), col_index++);
_get_table_field_data_string(result, &(p_data_tbl[i].preview_text), 1, col_index++);
_get_table_field_data_int (result, &(p_data_tbl[i].meeting_request_status), col_index++);
+ _get_table_field_data_int (result, &(p_data_tbl[i].message_class), col_index++);
+ _get_table_field_data_int (result, &(p_data_tbl[i].digest_type), col_index++);
+ _get_table_field_data_int (result, &(p_data_tbl[i].smime_type), col_index++);
/* check real body file... */
if (p_data_tbl[i].body_download_status) {
struct stat buf;
return ret;
}
+INTERNAL_FUNC int emstorage_query_mailbox_tbl(const char *input_conditional_clause, int input_get_mail_count, int input_transaction, emstorage_mailbox_tbl_t **output_mailbox_list, int *output_mailbox_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_get_mail_count[%d], input_transaction[%d], output_mailbox_list[%p], output_mailbox_count[%d]", input_conditional_clause, input_get_mail_count, input_transaction, output_mailbox_list, output_mailbox_count);
+
+ int i = 0;
+ int rc;
+ int count = 0;
+ int col_index = 0;
+ int error = EMAIL_ERROR_NONE;
+ int read_count = 0;
+ int total_count = 0;
+ char **result;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size, last_sync_time ";
+ emstorage_mailbox_tbl_t* p_data_tbl = NULL;
+ DB_STMT hStmt = NULL;
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ EMSTORAGE_START_READ_TRANSACTION(input_transaction);
+
+ if (input_get_mail_count == 0) { /* without mail count */
+ col_index = 12;
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl AS MBT %s", fields, input_conditional_clause);
+ }
+ else { /* with read count and total count */
+ col_index = 14;
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name %s", fields, input_conditional_clause);
+ }
+
+ EM_DEBUG_LOG("query[%s]", sql_query_string);
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
+
+ EM_DEBUG_LOG("result count [%d]", count);
+
+ if(count == 0) {
+ EM_DEBUG_EXCEPTION("Can't find mailbox");
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ if ((p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t) * count)) == NULL) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ for (i = 0; i < count; i++) {
+ _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
+ _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _get_table_field_data_int(result, (int*)&(p_data_tbl[i].mailbox_type), col_index++);
+ _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
+ _get_table_field_data_int(result, (int*)&(p_data_tbl[i].last_sync_time), col_index++);
+
+ if (input_get_mail_count == 1) {
+ _get_table_field_data_int(result, &(total_count), col_index++);
+ p_data_tbl[i].total_mail_count_on_local = total_count;
+ _get_table_field_data_int(result, &(read_count), col_index++);
+ p_data_tbl[i].unread_count = total_count - read_count; /* return unread count, NOT */
+ }
+ }
+
+
+FINISH_OFF:
+ if (result)
+ sqlite3_free_table(result);
+
+ if (error == EMAIL_ERROR_NONE) {
+ *output_mailbox_list = p_data_tbl;
+ *output_mailbox_count = count;
+ EM_DEBUG_LOG("Mailbox Count [ %d]", count);
+ }
+ else if (p_data_tbl != NULL)
+ emstorage_free_mailbox(&p_data_tbl, count, NULL);
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
+ _DISCONNECT_DB;
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
/* Query series --------------------------------------------------------------*/
-INTERNAL_FUNC int emstorage_check_duplicated_account(emf_account_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_check_duplicated_account(email_account_t* account, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
if (!account) {
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char **result;
int count;
char sql_query_string[QUERY_SIZE] = {0, };
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"SELECT COUNT(*) FROM mail_account_tbl "
" WHERE "
- " email_addr = '%s' AND "
- " user_name = '%s' AND "
- " receiving_server_type = %d AND "
- " receiving_server_addr = '%s' AND "
- " sending_user = '%s' AND "
- " sending_server_type = %d AND "
- " sending_server_addr = '%s'; ",
- account->email_addr,
- account->user_name, account->receiving_server_type, account->receiving_server_addr,
- account->sending_user, account->sending_server_type, account->sending_server_addr
+ " user_email_address = '%s' AND "
+ " incoming_server_user_name = '%s' AND "
+ " incoming_server_type = %d AND "
+ " incoming_server_address = '%s' AND "
+ " outgoing_server_user_name = '%s' AND "
+ " outgoing_server_type = %d AND "
+ " outgoing_server_address = '%s'; ",
+ account->user_email_address,
+ account->incoming_server_user_name, account->incoming_server_type, account->incoming_server_address,
+ account->outgoing_server_user_name, account->outgoing_server_type, account->outgoing_server_address
);
EM_DEBUG_LOG("Query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
count = atoi(result[1]);
if (count == 0) { /* not duplicated account */
ret = true;
- EM_DEBUG_LOG("NOT duplicated account: email_addr[%s]", account->email_addr);
+ EM_DEBUG_LOG("NOT duplicated account: user_email_address[%s]", account->user_email_address);
}
else { /* duplicated account */
ret = false;
- EM_DEBUG_LOG("The same account already exists. Duplicated account: email_addr[%s]", account->email_addr);
- error = EMF_ERROR_ALREADY_EXISTS;
+ EM_DEBUG_LOG("The same account already exists. Duplicated account: user_email_address[%s]", account->user_email_address);
+ error = EMAIL_ERROR_ALREADY_EXISTS;
}
FINISH_OFF:
if (!count) {
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EM_DEBUG_LOG("SQL STMT [ %s ]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
*count = sqlite3_column_int(hStmt, 0);
hStmt=NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d: %s", rc, err_msg);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
}
EM_DEBUG_FUNC_BEGIN();
int i = 0, count = 0, rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int field_index = 0;
+ int error = EMAIL_ERROR_NONE;
emstorage_account_tbl_t *p_data_tbl = NULL;
-
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *sql = "SELECT count(*) FROM mail_account_tbl;";
+ char **result;
+ sqlite3 *local_db_handle = NULL;
DB_STMT hStmt = NULL;
if (!select_num || !account_list) {
EM_DEBUG_EXCEPTION("select_num[%p], account_list[%p]", select_num, account_list);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- sqlite3 *local_db_handle = emstorage_get_db_connection();
+ local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- char sql_query_string[QUERY_SIZE] = {0, };
- char *sql = "SELECT count(*) FROM mail_account_tbl;";
- char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
count = atoi(result[1]);
sqlite3_free_table(result);
- if (!count) {
+ EM_DEBUG_LOG("count = %d", rc);
+
+ if (count == 0) {
EM_DEBUG_EXCEPTION("no account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
ret = true;
goto FINISH_OFF;
}
- EM_DEBUG_LOG("count = %d", rc);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_account_tbl ORDER BY account_id");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
count = 0;
ret = true;
goto FINISH_OFF;
if (!(p_data_tbl = (emstorage_account_tbl_t*)malloc(sizeof(emstorage_account_tbl_t) * count))) {
EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
memset(p_data_tbl, 0x00, sizeof(emstorage_account_tbl_t) * count);
for (i = 0; i < count; i++) {
/* get recordset */
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_bind_type), ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].account_name), 0, ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].receiving_server_type), RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].receiving_server_addr), 0, RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].email_addr), 0, EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_name), 0, USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].password), 0, PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].retrieval_mode), RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].port_num), PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].use_security), USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_server_type), SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].sending_server_addr), 0, SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_port_num), SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_auth), SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sending_security), SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].sending_user), 0, SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].sending_password), 0, SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].display_name), 0, DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].reply_to_addr), 0, REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].return_addr), 0, RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].keep_on_server), KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].pop_before_smtp), POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].apop), APOP_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].logo_icon_path), 0, LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].preset_account), PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].target_storage), TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].check_interval), CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.priority), PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.keep_local_copy), KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_delivery_receipt), REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_read_receipt), REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.download_limit), DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_address), BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_subject), BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.display_name_from), 0, DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.reply_with_body), REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.forward_with_files), FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_myname_card), ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_signature), ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.signature), 0, SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_my_address_to_bcc), ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].my_account_id), MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].index_color), INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL);
+ field_index = 0;
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].account_id), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].account_name), 0, field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].logo_icon_path), 0, field_index++);
+ _get_stmt_field_data_blob(hStmt, &(p_data_tbl[i].user_data), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].user_data_length), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].account_svc_id), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].sync_status), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].sync_disabled), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].default_mail_slot_size), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_display_name), 0, field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].user_email_address), 0, field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].reply_to_address), 0, field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].return_address), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].incoming_server_type), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].incoming_server_address), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_port_number), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].incoming_server_user_name), 0, field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].incoming_server_password), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_secure_connection), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].retrieval_mode), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].keep_mails_on_pop_server_after_download), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].check_interval), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].auto_download_size), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].outgoing_server_type), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].outgoing_server_address), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_port_number), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].outgoing_server_user_name), 0, field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].outgoing_server_password), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_secure_connection), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_need_authentication), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].outgoing_server_use_same_authenticator), field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].options.priority), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.keep_local_copy), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_delivery_receipt), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.req_read_receipt), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.download_limit), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_address), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.block_subject), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.display_name_from), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.reply_with_body), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.forward_with_files), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_myname_card), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].options.add_signature), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].options.signature), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl[i].options.add_my_address_to_bcc), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].pop_before_smtp), field_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].incoming_server_requires_apop), field_index++);
+ _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].smime_type), field_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].certificate_path), 0, field_index++);
+ _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].cipher_type), field_index++);
+ _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].digest_type), field_index++);
+
if (with_password == true) {
/* get password from the secure storage */
- char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];/* = p_data_tbl[i].password; */
- char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];;/* = p_data_tbl[i].sending_password; */
+ char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
- EM_SAFE_FREE(p_data_tbl[i].password);
- EM_SAFE_FREE(p_data_tbl[i].sending_password);
+ EM_SAFE_FREE(p_data_tbl[i].incoming_server_password);
+ EM_SAFE_FREE(p_data_tbl[i].outgoing_server_password);
/* get password file name */
- if ((error = _get_password_file_name(p_data_tbl[i].account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
+ if ((error = _get_password_file_name(p_data_tbl[i].account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("_get_password_file_name failed. [%d]", error);
+ error = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
goto FINISH_OFF;
}
/* read password from secure storage */
- if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl[i].password))) < 0 ) {
- EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed...");
+ if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl[i].incoming_server_password))) < 0 ) {
+ EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed. [%d]", error);
+ error = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
goto FINISH_OFF;
}
- EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name, p_data_tbl[i].password);
+ EM_DEBUG_LOG("recv_password_file_name[%s], incoming_server_password[%s]", recv_password_file_name, p_data_tbl[i].incoming_server_password);
- if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl[i].sending_password))) < 0) {
- EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed...");
+ if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl[i].outgoing_server_password))) < 0) {
+ EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed. [%d]", error);
+ error = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
goto FINISH_OFF;
}
- EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl[i].sending_password);
+ EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl[i].outgoing_server_password);
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i, rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
}
}
else if (p_data_tbl != NULL)
emstorage_free_account(&p_data_tbl, count, NULL);
+
if (hStmt != NULL) {
EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
hStmt = NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
_DISCONNECT_DB;
-
+
if (err_code != NULL)
*err_code = error;
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]", account_id, server_mail_id, mail, transaction, err_code);
- int ret = false, error = EMF_ERROR_NONE, result_count;
+ int ret = false, error = EMAIL_ERROR_NONE, result_count;
char conditional_clause[QUERY_SIZE] = {0, };
emstorage_mail_tbl_t* p_data_tbl = NULL;
if (!server_mail_id || !mail) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- error = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
}
-static int _write_conditional_clause_for_getting_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, char *conditional_clause_string, int buffer_size, int *err_code)
+static int _write_conditional_clause_for_getting_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, bool input_except_delete_flagged_mails, char *conditional_clause_string, int buffer_size, int *err_code)
{
int cur_clause = 0, conditional_clause_count = 0, i = 0;
if (account_id < ALL_ACCOUNT) {
EM_DEBUG_EXCEPTION("Invalid account_id [%d]", account_id);
- EM_RETURN_ERR_CODE(err_code, EMF_ERROR_INVALID_PARAM, false);
+ EM_RETURN_ERR_CODE(err_code, EMAIL_ERROR_INVALID_PARAM, false);
}
/* where clause */
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND account_id = %d", account_id);
}
- if (mailbox_name) {
+ if (mailbox_id > 0) {
cur_clause += (conditional_clause_count++ == 0)?
- SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE UPPER(mailbox_name) = UPPER('%s')", mailbox_name):
- SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE mailbox_id = %d", mailbox_id):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND mailbox_id = %d", mailbox_id);
}
else if(account_id != ALL_ACCOUNT) {
cur_clause += (conditional_clause_count++ == 0)?
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE thread_id = %d ", thread_id):
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND thread_id = %d ", thread_id);
}
- else if (thread_id == EMF_LIST_TYPE_THREAD) {
+ else if (thread_id == EMAIL_LIST_TYPE_THREAD) {
cur_clause += (conditional_clause_count++ == 0)?
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE thread_item_count > 0"):
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND thread_item_count > 0");
}
- else if (thread_id == EMF_LIST_TYPE_LOCAL) {
+ else if (thread_id == EMAIL_LIST_TYPE_LOCAL) {
cur_clause += (conditional_clause_count++ == 0)?
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE server_mail_status = 0"):
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND server_mail_status = 0");
}
- else if (thread_id == EMF_LIST_TYPE_UNREAD) {
+ else if (thread_id == EMAIL_LIST_TYPE_UNREAD) {
cur_clause += (conditional_clause_count++ == 0)?
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE flags_seen_field == 0"):
SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND flags_seen_field == 0");
}
}
+ if (input_except_delete_flagged_mails) {
+ cur_clause += (conditional_clause_count++ == 0)?
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " WHERE flags_deleted_field = 0"):
+ SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " AND flags_deleted_field = 0");
+ }
+
if (search_value) {
switch (search_type) {
- case EMF_SEARCH_FILTER_SUBJECT:
+ case EMAIL_SEARCH_FILTER_SUBJECT:
cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
- " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
+ " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
break;
- case EMF_SEARCH_FILTER_SENDER:
+ case EMAIL_SEARCH_FILTER_SENDER:
cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
- " %s ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " %s ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
") ", conditional_clause_count++ ? "AND" : "WHERE", search_value);
break;
- case EMF_SEARCH_FILTER_RECIPIENT:
+ case EMAIL_SEARCH_FILTER_RECIPIENT:
cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
- " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
- " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
- " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+ " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+ " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
") ", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value);
break;
- case EMF_SEARCH_FILTER_ALL:
+ case EMAIL_SEARCH_FILTER_ALL:
cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause,
- " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') "
- " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
- " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
- " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
- " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
+ " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\' "
+ " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+ " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+ " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
+ " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') "
" ) "
" )"
")", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value, search_value, search_value);
/* EM_DEBUG_LOG("where clause [%s]", conditional_clause_string); */
static char sorting_str[][50] = {
- " ORDER BY date_time DESC", /* case EMF_SORT_DATETIME_HIGH: */
- " ORDER BY date_time ASC", /* case EMF_SORT_DATETIME_LOW: */
- " ORDER BY full_address_from DESC, date_time DESC", /* case EMF_SORT_SENDER_HIGH: */
- " ORDER BY full_address_from ASC, date_time DESC", /* case EMF_SORT_SENDER_LOW: */
- " ORDER BY full_address_to DESC, date_time DESC", /* case EMF_SORT_RCPT_HIGH: */
- " ORDER BY full_address_to ASC, date_time DESC", /* case EMF_SORT_RCPT_LOW: */
- " ORDER BY subject DESC, date_time DESC", /* case EMF_SORT_SUBJECT_HIGH: */
- " ORDER BY subject ASC, date_time DESC", /* case EMF_SORT_SUBJECT_LOW: */
- " ORDER BY priority DESC, date_time DESC", /* case EMF_SORT_PRIORITY_HIGH: */
- " ORDER BY priority ASC, date_time DESC", /* case EMF_SORT_PRIORITY_LOW: */
- " ORDER BY attachment_count DESC, date_time DESC", /* case EMF_SORT_ATTACHMENT_HIGH: */
- " ORDER BY attachment_count ASC, date_time DESC", /* case EMF_SORT_ATTACHMENT_LOW: */
- " ORDER BY lock_status DESC, date_time DESC", /* case EMF_SORT_FAVORITE_HIGH: */
- " ORDER BY lock_status ASC, date_time DESC", /* case EMF_SORT_FAVORITE_LOW: */
- " ORDER BY mailbox_name DESC, date_time DESC", /* case EMF_SORT_MAILBOX_NAME_HIGH: */
- " ORDER BY mailbox_name ASC, date_time DESC" /* case EMF_SORT_MAILBOX_NAME_LOW: */
+ " ORDER BY date_time DESC", /* case EMAIL_SORT_DATETIME_HIGH: */
+ " ORDER BY date_time ASC", /* case EMAIL_SORT_DATETIME_LOW: */
+ " ORDER BY full_address_from DESC, date_time DESC", /* case EMAIL_SORT_SENDER_HIGH: */
+ " ORDER BY full_address_from ASC, date_time DESC", /* case EMAIL_SORT_SENDER_LOW: */
+ " ORDER BY full_address_to DESC, date_time DESC", /* case EMAIL_SORT_RCPT_HIGH: */
+ " ORDER BY full_address_to ASC, date_time DESC", /* case EMAIL_SORT_RCPT_LOW: */
+ " ORDER BY subject DESC, date_time DESC", /* case EMAIL_SORT_SUBJECT_HIGH: */
+ " ORDER BY subject ASC, date_time DESC", /* case EMAIL_SORT_SUBJECT_LOW: */
+ " ORDER BY priority DESC, date_time DESC", /* case EMAIL_SORT_PRIORITY_HIGH: */
+ " ORDER BY priority ASC, date_time DESC", /* case EMAIL_SORT_PRIORITY_LOW: */
+ " ORDER BY attachment_count DESC, date_time DESC", /* case EMAIL_SORT_ATTACHMENT_HIGH: */
+ " ORDER BY attachment_count ASC, date_time DESC", /* case EMAIL_SORT_ATTACHMENT_LOW: */
+ " ORDER BY lock_status DESC, date_time DESC", /* case EMAIL_SORT_FAVORITE_HIGH: */
+ " ORDER BY lock_status ASC, date_time DESC", /* case EMAIL_SORT_FAVORITE_LOW: */
+ " ORDER BY mailbox_name DESC, date_time DESC", /* case EMAIL_SORT_MAILBOX_NAME_HIGH: */
+ " ORDER BY mailbox_name ASC, date_time DESC" /* case EMAIL_SORT_MAILBOX_NAME_LOW: */
};
- if (sorting < EMF_SORT_END && sorting >= 0)
+ if (sorting < EMAIL_SORT_END && sorting >= 0)
cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size, " %s", sorting_str[sorting]);
else
EM_DEBUG_LOG(" Invalid Sorting order ");
*
*
*/
-INTERNAL_FUNC int emstorage_get_mail_list(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_mail_list(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(emstorage_get_mail_list_func);
- int ret = false, error = EMF_ERROR_NONE;
+ int ret = false, error = EMAIL_ERROR_NONE;
char conditional_clause_string[QUERY_SIZE] = { 0, };
if (account_id < ALL_ACCOUNT) {
EM_DEBUG_EXCEPTION("Invalid account_id [%d]", account_id);
- EM_RETURN_ERR_CODE(err_code, EMF_ERROR_INVALID_PARAM, false);
+ EM_RETURN_ERR_CODE(err_code, EMAIL_ERROR_INVALID_PARAM, false);
}
EM_IF_NULL_RETURN_VALUE(result_count, false);
- _write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, addr_list, thread_id, start_index, limit_count, search_type, search_value, sorting, conditional_clause_string, QUERY_SIZE, &error);
+ _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, addr_list, thread_id, start_index, limit_count, search_type, search_value, sorting, true, conditional_clause_string, QUERY_SIZE, &error);
EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
*
*
*/
-INTERNAL_FUNC int emstorage_get_mails(int account_id, const char *mailbox_name, emf_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_mails(int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(emStorageGetMails);
- int count = 0, ret = false, error = EMF_ERROR_NONE;
+ int count = 0, ret = false, error = EMAIL_ERROR_NONE;
emstorage_mail_tbl_t *p_data_tbl = NULL;
char conditional_clause_string[QUERY_SIZE] = {0, };
EM_IF_NULL_RETURN_VALUE(result_count, false);
if (!result_count || !mail_list || account_id < ALL_ACCOUNT) {
- 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;
}
- _write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, addr_list, thread_id, start_index, limit_count, 0, NULL, sorting, conditional_clause_string, QUERY_SIZE, &error);
+ _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, addr_list, thread_id, start_index, limit_count, 0, NULL, sorting, true, conditional_clause_string, QUERY_SIZE, &error);
EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
*
*
*/
-INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, const char *mailbox_name, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, emf_sort_type_t sorting, int transaction, emf_mail_list_item_t** mail_list, int *result_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_searched_mail_list(int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
- int ret = false, error = EMF_ERROR_NONE;
+ int ret = false, error = EMAIL_ERROR_NONE;
char conditional_clause[QUERY_SIZE] = {0, };
-
+ char *temp_search_value = (char *)search_value;
+
EM_IF_NULL_RETURN_VALUE(mail_list, false);
EM_IF_NULL_RETURN_VALUE(result_count, false);
if (!result_count || !mail_list || account_id < ALL_ACCOUNT) {
EM_DEBUG_EXCEPTION("select_num[%p], Mail_list[%p]", result_count, mail_list);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- _write_conditional_clause_for_getting_mail_list(account_id, mailbox_name, NULL, thread_id, start_index, limit_count, search_type, search_value, sorting, conditional_clause, QUERY_SIZE, &error);
+ temp_search_value = em_replace_all_string(temp_search_value, "_", "\\_");
+ temp_search_value = em_replace_all_string(temp_search_value, "%", "\\%");
+
+ _write_conditional_clause_for_getting_mail_list(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, search_type, temp_search_value, sorting, true, conditional_clause, QUERY_SIZE, &error);
EM_DEBUG_LOG("conditional_clause[%s]", conditional_clause);
if (account_id <= 0 || !recv_password_file_name || !send_password_file_name) {
EM_DEBUG_EXCEPTION("Invalid parameter");
- return EMF_ERROR_INVALID_PARAM;
+ return EMAIL_ERROR_INVALID_PARAM;
}
sprintf(recv_password_file_name, ".email_account_%d_recv", account_id);
sprintf(send_password_file_name, ".email_account_%d_send", account_id);
EM_DEBUG_FUNC_END();
- return EMF_ERROR_NONE;
+ return EMAIL_ERROR_NONE;
}
static int _read_password_from_secure_storage(char *file_name, char **password)
if (!file_name || !password) {
EM_DEBUG_EXCEPTION("Invalid Parameter");
- return EMF_ERROR_INVALID_PARAM;
+ return EMAIL_ERROR_INVALID_PARAM;
}
size_t buf_len = 0, read_len = 0;
ssm_file_info_t sfi;
char *temp_password = NULL;
- int ret = EMF_ERROR_NONE;
+ int error_code_from_ssm = 0;
+ int ret = EMAIL_ERROR_NONE;
- if (ssm_getinfo(file_name, &sfi, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
- EM_DEBUG_EXCEPTION("ssm_getinfo() failed.");
- ret = EMF_ERROR_SYSTEM_FAILURE;
+ if ( (error_code_from_ssm = ssm_getinfo(file_name, &sfi, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_getinfo() failed. [%d]", error_code_from_ssm);
+ ret = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
goto FINISH_OFF;
}
EM_DEBUG_LOG("password buf_len[%d]", buf_len);
if ((temp_password = (char *)malloc(buf_len + 1)) == NULL) {
EM_DEBUG_EXCEPTION("malloc failed...");
-
- ret = EMF_ERROR_OUT_OF_MEMORY;
+ ret = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
memset(temp_password, 0x00, buf_len + 1);
- if (ssm_read(file_name, temp_password, buf_len, &read_len, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
- EM_DEBUG_EXCEPTION("ssm_read() failed.");
- ret = EMF_ERROR_SYSTEM_FAILURE;
+ if ( (error_code_from_ssm = ssm_read(file_name, temp_password, buf_len, &read_len, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_read() failed. [%d]", error_code_from_ssm);
+ ret = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
goto FINISH_OFF;
}
if (!account) {
EM_DEBUG_EXCEPTION("account_id[%d], account[%p]", account_id, account);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
emstorage_account_tbl_t* p_data_tbl = NULL;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
sql_len = strlen(sql_query_string);
- if (pulloption & EMF_ACC_GET_OPT_DEFAULT) {
- SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "account_bind_type, receiving_server_type, receiving_server_addr, email_addr, user_name, \
- retrieval_mode, port_num, use_security, sending_server_type, sending_server_addr, sending_port_num, sending_auth, sending_security, sending_user, \
- display_name, reply_to_addr, return_addr, account_id, keep_on_server, flag1, flag2, pop_before_smtp, apop, logo_icon_path, preset_account, target_storage, check_interval, index_color, sync_status, ");
+ if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) {
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len,
+ "incoming_server_type,"
+ "incoming_server_address,"
+ "user_email_address,"
+ "incoming_server_user_name,"
+ "retrieval_mode,"
+ "incoming_server_port_number,"
+ "incoming_server_secure_connection,"
+ "outgoing_server_type,"
+ "outgoing_server_address,"
+ "outgoing_server_port_number,"
+ "outgoing_server_need_authentication,"
+ "outgoing_server_secure_connection,"
+ "outgoing_server_user_name,"
+ "user_display_name,"
+ "reply_to_address,"
+ "return_address,"
+ "account_id,"
+ "keep_mails_on_pop_server_after_download,"
+ "auto_download_size,"
+ "outgoing_server_use_same_authenticator,"
+ "pop_before_smtp,"
+ "incoming_server_requires_apop,"
+ "logo_icon_path,"
+ "user_data,"
+ "user_data_length,"
+ "check_interval,"
+ "sync_status,");
sql_len = strlen(sql_query_string);
}
- if (pulloption & EMF_ACC_GET_OPT_ACCOUNT_NAME) {
+ if (pulloption & EMAIL_ACC_GET_OPT_ACCOUNT_NAME) {
SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " account_name, ");
sql_len = strlen(sql_query_string);
}
/* get from secure storage, not from db */
- if (pulloption & EMF_ACC_GET_OPT_OPTIONS) {
- SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, " priority, keep_local_copy, req_delivery_receipt, req_read_receipt, download_limit, block_address, block_subject, display_name_from, \
- reply_with_body, forward_with_files, add_myname_card, add_signature, signature, add_my_address_to_bcc, my_account_id, ");
+ if (pulloption & EMAIL_ACC_GET_OPT_OPTIONS) {
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len,
+ "priority,"
+ "keep_local_copy,"
+ "req_delivery_receipt,"
+ "req_read_receipt,"
+ "download_limit,"
+ "block_address,"
+ "block_subject,"
+ "display_name_from,"
+ "reply_with_body,"
+ "forward_with_files,"
+ "add_myname_card,"
+ "add_signature,"
+ "signature,"
+ "add_my_address_to_bcc,"
+ "account_svc_id,"
+ "sync_disabled,"
+ "default_mail_slot_size,"
+ "smime_type,"
+ "certificate_path,"
+ "cipher_type,"
+ "digest_type,");
+
sql_len = strlen(sql_query_string);
}
+
/* dummy value, FROM WHERE clause */
SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "0 FROM mail_account_tbl WHERE account_id = %d", account_id);
/* execute a sql and count rows */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no matched account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
goto FINISH_OFF;
}
/* Assign query result to structure */
if (!(p_data_tbl = (emstorage_account_tbl_t *)malloc(sizeof(emstorage_account_tbl_t) * 1))) {
EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
memset(p_data_tbl, 0x00, sizeof(emstorage_account_tbl_t) * 1);
int col_index = 0;
- if (pulloption & EMF_ACC_GET_OPT_DEFAULT) {
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_bind_type), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->receiving_server_type), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->receiving_server_addr), 0, col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_addr), 0, col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->user_name), 0, col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->retrieval_mode), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->port_num), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->use_security), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_server_type), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->sending_server_addr), 0, col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_port_num), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_auth), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->sending_security), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->sending_user), 0, col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->display_name), 0, col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->reply_to_addr), 0, col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->return_addr), 0, col_index++);
+ if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) {
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->incoming_server_type), col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->incoming_server_address), 0, col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->user_email_address), 0, col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->incoming_server_user_name), 0, col_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->retrieval_mode), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_port_number), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_secure_connection), col_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->outgoing_server_type), col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->outgoing_server_address), 0, col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_port_number), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_need_authentication), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_secure_connection), col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->outgoing_server_user_name), 0, col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->user_display_name), 0, col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->reply_to_address), 0, col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->return_address), 0, col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->keep_on_server), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag1), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->flag2), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->keep_mails_on_pop_server_after_download), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->auto_download_size), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->outgoing_server_use_same_authenticator), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->pop_before_smtp), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->apop), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->incoming_server_requires_apop), col_index++);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->logo_icon_path), 0, col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->preset_account), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->target_storage), col_index++);
+ _get_stmt_field_data_blob(hStmt, &p_data_tbl->user_data, col_index++);
+ _get_stmt_field_data_int(hStmt, &p_data_tbl->user_data_length, col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->check_interval), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->index_color), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->sync_status), col_index++);
}
- if (pulloption & EMF_ACC_GET_OPT_ACCOUNT_NAME)
+ if (pulloption & EMAIL_ACC_GET_OPT_ACCOUNT_NAME)
_get_stmt_field_data_string(hStmt, &(p_data_tbl->account_name), 0, col_index++);
- if (pulloption & EMF_ACC_GET_OPT_PASSWORD) {
+ if (pulloption & EMAIL_ACC_GET_OPT_PASSWORD) {
/* get password file name */
- if ((error = _get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
+ if ((error = _get_password_file_name(p_data_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("_get_password_file_name failed. [%d]", error);
goto FINISH_OFF;
}
/* read password from secure storage */
- if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl->password))) < 0) {
- EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed...");
+ if ((error = _read_password_from_secure_storage(recv_password_file_name, &(p_data_tbl->incoming_server_password))) < 0) {
+ EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed. [%d]", error);
goto FINISH_OFF;
}
- EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name, p_data_tbl->password);
+
+ EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", recv_password_file_name, p_data_tbl->incoming_server_password);
- if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl->sending_password))) < 0) {
- EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed...");
+ if ((error = _read_password_from_secure_storage(send_password_file_name, &(p_data_tbl->outgoing_server_password))) < 0) {
+ EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed. [%d]", error);
goto FINISH_OFF;
}
- EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl->sending_password);
+ EM_DEBUG_LOG("send_password_file_name[%s], password[%s]", send_password_file_name, p_data_tbl->outgoing_server_password);
}
- if (pulloption & EMF_ACC_GET_OPT_OPTIONS) {
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.priority), col_index++);
+ if (pulloption & EMAIL_ACC_GET_OPT_OPTIONS) {
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.priority), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->options.keep_local_copy), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->options.req_delivery_receipt), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->options.req_read_receipt), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_myname_card), col_index++);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_signature), col_index++);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->options.signature), 0, col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->options.add_my_address_to_bcc), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->my_account_id), col_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->options.add_my_address_to_bcc), col_index++);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_svc_id), col_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->sync_disabled), col_index++);
+ _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->default_mail_slot_size), col_index++);
+ _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->smime_type), col_index++);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->certificate_path), 0, col_index++);
+ _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->cipher_type), col_index++);
+ _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->digest_type), col_index++);
}
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_FUNC_BEGIN("account_id[%d], password_length[%p], err_code[%p]", account_id, password_length, err_code);
if (account_id <= 0 || password_length == NULL) {
- EM_DEBUG_EXCEPTION("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;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
char *temp_password = NULL;
/* get password file name */
- if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+ if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
return ret;
}
-INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_account(int account_id, emstorage_account_tbl_t* account_tbl, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], account[%p], transaction[%d], err_code[%p]", account_id, account_tbl, transaction, err_code);
- if (account_id < FIRST_ACCOUNT_ID || !account) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (account_id < FIRST_ACCOUNT_ID || !account_tbl) {
+ 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;
}
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc, ret = false;
DB_STMT hStmt = NULL;
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_account_tbl SET"
- " account_bind_type = ?"
- ", account_name = ?"
- ", receiving_server_type = ?"
- ", receiving_server_addr = ?"
- ", email_addr = ?"
- ", user_name = ?"
+ " account_name = ?"
+ ", logo_icon_path = ?"
+ ", user_data = ?"
+ ", user_data_length = ?"
+ ", account_svc_id = ?"
+ ", sync_status = ?"
+ ", sync_disabled = ?"
+ ", default_mail_slot_size = ?"
+ ", user_display_name = ?"
+ ", user_email_address = ?"
+ ", reply_to_address = ?"
+ ", return_address = ?"
+ ", incoming_server_type = ?"
+ ", incoming_server_address = ?"
+ ", incoming_server_port_number = ?"
+ ", incoming_server_user_name = ?"
+ ", incoming_server_secure_connection = ?"
", retrieval_mode = ?"
- ", port_num = ?"
- ", use_security = ?"
- ", sending_server_type = ?"
- ", sending_server_addr = ?"
- ", sending_port_num = ?"
- ", sending_auth = ?"
- ", sending_security = ?"
- ", sending_user = ?"
- ", display_name = ?"
- ", reply_to_addr = ?"
- ", return_addr = ?"
- ", keep_on_server = ?"
- ", flag1 = ?"
- ", flag2 = ?"
- ", pop_before_smtp = ?" /* POP before SMTP authentication */
- ", apop = ?" /* APOP authentication */
- ", logo_icon_path = ?" /* Receving Option : Account logo icon */
- ", preset_account = ?" /* Receving Option : Preset account or not */
- ", target_storage = ?" /* Receving Option : Specifies the targetStorage. 0 is phone, 1 is MMC */
- ", check_interval = ?" /* Receving Option : Specifies the check interval. Unit is minute */
- ", priority = ?" /* Sending Option : Specifies the prority. 1=high 3=normal 5=low */
- ", keep_local_copy = ?" /* Sending Option : */
- ", req_delivery_receipt = ?" /* Sending Option : */
- ", req_read_receipt = ?" /* Sending Option : */
- ", download_limit = ?" /* Sending Option : */
- ", block_address = ?" /* Sending Option : */
- ", block_subject = ?" /* Sending Option : */
- ", display_name_from = ?" /* Sending Option : */
- ", reply_with_body = ?" /* Sending Option : */
- ", forward_with_files = ?" /* Sending Option : */
- ", add_myname_card = ?" /* Sending Option : */
- ", add_signature = ?" /* Sending Option : */
- ", signature = ?" /* Sending Option : */
- ", add_my_address_to_bcc = ?" /* Sending Option : */
- ", my_account_id = ?" /* Support 'My Account' */
- ", index_color = ?" /* Index color */
- ", sync_status = ?" /* Sync Status */
+ ", keep_mails_on_pop_server_after_download = ?"
+ ", check_interval = ?"
+ ", auto_download_size = ?"
+ ", outgoing_server_type = ?"
+ ", outgoing_server_address = ?"
+ ", outgoing_server_port_number = ?"
+ ", outgoing_server_user_name = ?"
+ ", outgoing_server_secure_connection = ?"
+ ", outgoing_server_need_authentication = ?"
+ ", outgoing_server_use_same_authenticator = ?"
+ ", priority = ?"
+ ", keep_local_copy = ?"
+ ", req_delivery_receipt = ?"
+ ", req_read_receipt = ?"
+ ", download_limit = ?"
+ ", block_address = ?"
+ ", block_subject = ?"
+ ", display_name_from = ?"
+ ", reply_with_body = ?"
+ ", forward_with_files = ?"
+ ", add_myname_card = ?"
+ ", add_signature = ?"
+ ", signature = ?"
+ ", add_my_address_to_bcc = ?"
+ ", pop_before_smtp = ?"
+ ", incoming_server_requires_apop = ?"
+ ", smime_type = ?"
+ ", certificate_path = ?"
+ ", cipher_type = ?"
+ ", digest_type = ?"
" WHERE account_id = ?");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_LOG("SQL[%s]", sql_query_string);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_prepare fail:(%d) %s", rc, sqlite3_errmsg(local_db_handle)));
int i = 0;
-
- _bind_stmt_field_data_int(hStmt, i++, account->account_bind_type);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, i++, account->receiving_server_type);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->receiving_server_addr, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->email_addr, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, i++, account->retrieval_mode);
- _bind_stmt_field_data_int(hStmt, i++, account->port_num);
- _bind_stmt_field_data_int(hStmt, i++, account->use_security);
- _bind_stmt_field_data_int(hStmt, i++, account->sending_server_type);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->sending_server_addr, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, i++, account->sending_port_num);
- _bind_stmt_field_data_int(hStmt, i++, account->sending_auth);
- _bind_stmt_field_data_int(hStmt, i++, account->sending_security);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->sending_user, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->reply_to_addr, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)account->return_addr, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, i++, account->keep_on_server);
- _bind_stmt_field_data_int(hStmt, i++, account->flag1);
- _bind_stmt_field_data_int(hStmt, i++, account->flag2);
- _bind_stmt_field_data_int(hStmt, i++, account->pop_before_smtp);
- _bind_stmt_field_data_int(hStmt, i++, account->apop);
- _bind_stmt_field_data_string(hStmt, i++, account->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, i++, account->preset_account);
- _bind_stmt_field_data_int(hStmt, i++, account->target_storage);
- _bind_stmt_field_data_int(hStmt, i++, account->check_interval);
- _bind_stmt_field_data_int(hStmt, i++, account->options.priority);
- _bind_stmt_field_data_int(hStmt, i++, account->options.keep_local_copy);
- _bind_stmt_field_data_int(hStmt, i++, account->options.req_delivery_receipt);
- _bind_stmt_field_data_int(hStmt, i++, account->options.req_read_receipt);
- _bind_stmt_field_data_int(hStmt, i++, account->options.download_limit);
- _bind_stmt_field_data_int(hStmt, i++, account->options.block_address);
- _bind_stmt_field_data_int(hStmt, i++, account->options.block_subject);
- _bind_stmt_field_data_string(hStmt, i++, account->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, i++, account->options.reply_with_body);
- _bind_stmt_field_data_int(hStmt, i++, account->options.forward_with_files);
- _bind_stmt_field_data_int(hStmt, i++, account->options.add_myname_card);
- _bind_stmt_field_data_int(hStmt, i++, account->options.add_signature);
- _bind_stmt_field_data_string(hStmt, i++, account->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
- if (account->options.add_my_address_to_bcc != 0)
- account->options.add_my_address_to_bcc = 1;
- _bind_stmt_field_data_int(hStmt, i++, account->options.add_my_address_to_bcc);
- _bind_stmt_field_data_int(hStmt, i++, account->my_account_id);
- _bind_stmt_field_data_int(hStmt, i++, account->index_color);
- _bind_stmt_field_data_int(hStmt, i++, account->sync_status);
+
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_blob(hStmt, i++, account_tbl->user_data, account_tbl->user_data_length);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->user_data_length);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_svc_id);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_status);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_disabled);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->default_mail_slot_size);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_email_address, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->reply_to_address, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->return_address, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_type);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_address, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_port_number);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_secure_connection);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->retrieval_mode);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->keep_mails_on_pop_server_after_download);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->check_interval);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->auto_download_size);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_type);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_address, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_port_number);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_user_name, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_secure_connection);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_need_authentication);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_use_same_authenticator);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.priority);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.keep_local_copy);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_delivery_receipt);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_read_receipt);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.download_limit);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_address);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_subject);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.reply_with_body);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.forward_with_files);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_myname_card);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_signature);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_my_address_to_bcc);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->pop_before_smtp);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_requires_apop);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->smime_type);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->certificate_path, 0, CERTIFICATE_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type);
_bind_stmt_field_data_int(hStmt, i++, account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
/* validate account existence */
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
goto FINISH_OFF;
}
/* get password file name */
- if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+ if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
/* save passwords to the secure storage */
- EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account->password, send_password_file_name, account->sending_password);
- if (account->password && (strlen(account->password) > 0)) {
- if (ssm_write_buffer(account->password, strlen(account->password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
- EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -recv password : file[%s]", recv_password_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account_tbl->incoming_server_password, send_password_file_name, account_tbl->outgoing_server_password);
+ if (account_tbl->incoming_server_password && (strlen(account_tbl->incoming_server_password) > 0)) {
+ if (ssm_write_buffer(account_tbl->incoming_server_password, strlen(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -recv incoming_server_password : file[%s]", recv_password_file_name);
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
- if (account->sending_password && (strlen(account->sending_password) > 0)) {
- if (ssm_write_buffer(account->sending_password, strlen(account->sending_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ if (account_tbl->outgoing_server_password && (strlen(account_tbl->outgoing_server_password) > 0)) {
+ if (ssm_write_buffer(account_tbl->outgoing_server_password, strlen(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
EM_DEBUG_EXCEPTION(" ssm_write_buffer failed -send password : file[%s]", send_password_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
- if (!emstorage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account->account_id, 0, NULL, 0))
+ if (!emstorage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account_tbl->account_id, 0, NULL, 0))
EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event[ NOTI_ACCOUNT_UPDATE] : Notification Failed >>> ");
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
+INTERNAL_FUNC int emstorage_set_field_of_accounts_with_integer_value(int account_id, char *field_name, int value, int transaction)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], field_name[%s], value[%d], transaction[%d]", account_id, field_name, value, transaction);
+ int error = EMAIL_ERROR_NONE;
+ int rc = 0;
+ int result = 0;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = NULL;
+
+ if (!account_id || !field_name) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ local_db_handle = emstorage_get_db_connection();
+
+ /* Write query string */
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_account_tbl SET %s = %d WHERE account_id = %d", field_name, value, account_id);
+
+ EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+ /* Execute query */
+ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ if (sqlite3_changes(local_db_handle) == 0)
+ EM_DEBUG_LOG("no mail matched...");
+
+
+FINISH_OFF:
+ result = (error == EMAIL_ERROR_NONE) ? true : false;
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, result, error);
+ _DISCONNECT_DB;
+
+ if (!emstorage_notify_storage_event(NOTI_ACCOUNT_UPDATE, account_id, 0, field_name, value))
+ EM_DEBUG_EXCEPTION("emstorage_notify_storage_event failed : NOTI_ACCOUNT_UPDATE [%s,%d]", field_name, value);
+
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
+
INTERNAL_FUNC int emstorage_get_sync_status_of_account(int account_id, int *result_sync_status,int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], result_sync_status [%p], err_code[%p]", account_id, result_sync_status, err_code);
if(!result_sync_status) {
- 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;
}
- int error = EMF_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index;
+ int error = EMAIL_ERROR_NONE, rc, ret = false, sync_status, count, i, col_index;
char sql_query_string[QUERY_SIZE] = {0, };
char **result = NULL;
sqlite3 *local_db_handle = emstorage_get_db_connection();
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT sync_status FROM mail_account_tbl");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (!count) {
EM_DEBUG_EXCEPTION("no matched account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
goto FINISH_OFF;
}
return ret;
}
-INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, emstorage_set_type_t set_operator, int sync_status, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_sync_status_of_account(int account_id, email_set_type_t set_operator, int sync_status, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], set_operator[%d], sync_status [%d], transaction[%d], err_code[%p]", account_id, set_operator, sync_status, transaction, err_code);
- int error = EMF_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status;
+ int error = EMAIL_ERROR_NONE, rc, ret = false, set_value = sync_status, result_sync_status;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
set_value = result_sync_status & (~set_value);
break;
default:
- EM_DEBUG_EXCEPTION("EMF_ERROR_NOT_SUPPORTED [%d]", set_operator);
- error = EMF_ERROR_NOT_SUPPORTED;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_NOT_SUPPORTED [%d]", set_operator);
+ error = EMAIL_ERROR_NOT_SUPPORTED;
break;
}
EM_DEBUG_LOG("set_value [%d]", set_value);
if(account_id)
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE account_id = %d", set_value, account_id);
else
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE receiving_server_type <> 5", set_value);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_account_tbl SET sync_status = %d WHERE incoming_server_type <> 5", set_value);
EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION("no matched account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
goto FINISH_OFF;
}
return ret;
}
-INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_account(emstorage_account_tbl_t* account_tbl, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code);
- if (!account) {
- EM_DEBUG_EXCEPTION("account[%p], transaction[%d], err_code[%p]", account, transaction, err_code);
+ if (!account_tbl) {
+ EM_DEBUG_EXCEPTION("account[%p], transaction[%d], err_code[%p]", account_tbl, transaction, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
+ int error_from_ssm = 0;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
char recv_password_file_name[MAX_PW_FILE_NAME_LENGTH];
char **result = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL==result[1]) rc = 1;
sqlite3_free_table(result);
result = NULL;
- account->account_id = rc;
+ account_tbl->account_id = rc;
- if ((error = _get_password_file_name(account->account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+ if ((error = _get_password_file_name(account_tbl->account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
- EM_DEBUG_LOG(" >>>> ACCOUNT_ID [ %d ] ", account->account_id);
+ EM_DEBUG_LOG(" >>>> ACCOUNT_ID [ %d ] ", account_tbl->account_id);
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"INSERT INTO mail_account_tbl VALUES "
"( "
- " ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? " /* password - for receving */
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? " /* sending_password */
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? " /* POP before SMTP authentication */
- " , ? " /* APOP Authentication */
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? "
- " , ? " /* add full_address_bcc */
- " , ? " /* my account id */
- " , ? " /* index_color */
- " , ? " /* Sync Status */
+ " ? " /* account_id */
+ " , ? " /* account_name */
+ " , ? " /* logo_icon_path */
+ " , ? " /* user_data */
+ " , ? " /* user_data_length */
+ " , ? " /* account_svc_id */
+ " , ? " /* sync_status */
+ " , ? " /* sync_disabled */
+ " , ? " /* default_mail_slot_size */
+ " , ? " /* user_display_name */
+ " , ? " /* user_email_address */
+ " , ? " /* reply_to_address */
+ " , ? " /* return_address */
+ " , ? " /* incoming_server_type */
+ " , ? " /* incoming_server_address */
+ " , ? " /* incoming_server_port_number */
+ " , ? " /* incoming_server_user_name */
+ " , ? " /* incoming_server_password */
+ " , ? " /* incoming_server_secure_connection */
+ " , ? " /* retrieval_mode */
+ " , ? " /* keep_mails_on_pop_server_after_download */
+ " , ? " /* check_interval */
+ " , ? " /* auto_download_size */
+ " , ? " /* outgoing_server_type */
+ " , ? " /* outgoing_server_address */
+ " , ? " /* outgoing_server_port_number */
+ " , ? " /* outgoing_server_user_name */
+ " , ? " /* outgoing_server_password */
+ " , ? " /* outgoing_server_secure_connection */
+ " , ? " /* outgoing_server_need_authentication */
+ " , ? " /* outgoing_server_use_same_authenticator */
+ " , ? " /* priority */
+ " , ? " /* keep_local_copy */
+ " , ? " /* req_delivery_receipt */
+ " , ? " /* req_read_receipt */
+ " , ? " /* download_limit */
+ " , ? " /* block_address */
+ " , ? " /* block_subject */
+ " , ? " /* display_name_from */
+ " , ? " /* reply_with_body */
+ " , ? " /* forward_with_files */
+ " , ? " /* add_myname_card */
+ " , ? " /* add_signature */
+ " , ? " /* signature */
+ " , ? " /* add_my_address_to_bcc */
+ " , ? " /* pop_before_smtp */
+ " , ? " /* incoming_server_requires_apop */
+ " , ? " /* smime_type */
+ " , ? " /* certificate_path */
+ " , ? " /* cipher_type */
+ " , ? " /* digest_type */
") ");
-
-
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
- _bind_stmt_field_data_int(hStmt, ACCOUNT_BIND_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->account_bind_type);
- _bind_stmt_field_data_string(hStmt, ACCOUNT_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, RECEIVING_SERVER_TYPE_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->receiving_server_type);
- _bind_stmt_field_data_string(hStmt, RECEIVING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->receiving_server_addr, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, EMAIL_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->email_addr, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, USER_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL, (char *)"", 0, PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, RETRIEVAL_MODE_IDX_IN_MAIL_ACCOUNT_TBL, account->retrieval_mode);
- _bind_stmt_field_data_int(hStmt, PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL, account->port_num);
- _bind_stmt_field_data_int(hStmt, USE_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL, account->use_security);
- _bind_stmt_field_data_int(hStmt, SENDING_SERVER_TYPE_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_server_type);
- _bind_stmt_field_data_string(hStmt, SENDING_SERVER_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->sending_server_addr, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, SENDING_PORT_NUM_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_port_num);
- _bind_stmt_field_data_int(hStmt, SENDING_AUTH_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_auth);
- _bind_stmt_field_data_int(hStmt, SENDING_SECURITY_IDX_IN_MAIL_ACCOUNT_TBL, account->sending_security);
- _bind_stmt_field_data_string(hStmt, SENDING_USER_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->sending_user, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, SENDING_PASSWORD_IDX_IN_MAIL_ACCOUNT_TBL, (char *)"", 0, SENDING_PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, DISPLAY_NAME_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, REPLY_TO_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->reply_to_addr, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_string(hStmt, RETURN_ADDR_IDX_IN_MAIL_ACCOUNT_TBL, (char *)account->return_addr, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL, account->account_id);
- _bind_stmt_field_data_int(hStmt, KEEP_ON_SERVER_IDX_IN_MAIL_ACCOUNT_TBL, account->keep_on_server);
- _bind_stmt_field_data_int(hStmt, FLAG1_IDX_IN_MAIL_ACCOUNT_TBL, account->flag1);
- _bind_stmt_field_data_int(hStmt, FLAG2_IDX_IN_MAIL_ACCOUNT_TBL, account->flag2);
- _bind_stmt_field_data_int(hStmt, POP_BEFORE_SMTP_IDX_IN_MAIL_ACCOUNT_TBL, account->pop_before_smtp); /* POP before SMTP authentication [deepam.p@siso.com] */
- _bind_stmt_field_data_int(hStmt, APOP_IDX_IN_MAIL_ACCOUNT_TBL, account->apop); /* APOP Support [deepam.p@siso.com] */
- _bind_stmt_field_data_string(hStmt, LOGO_ICON_PATH_IDX_IN_MAIL_ACCOUNT_TBL, account->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, PRESET_ACCOUNT_IDX_IN_MAIL_ACCOUNT_TBL, account->preset_account);
- _bind_stmt_field_data_int(hStmt, TARGET_STORAGE_IDX_IN_MAIL_ACCOUNT_TBL, account->target_storage);
- _bind_stmt_field_data_int(hStmt, CHECK_INTERVAL_IDX_IN_MAIL_ACCOUNT_TBL, account->check_interval);
- _bind_stmt_field_data_int(hStmt, PRIORITY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.priority);
- _bind_stmt_field_data_int(hStmt, KEEP_LOCAL_COPY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.keep_local_copy);
- _bind_stmt_field_data_int(hStmt, REQ_DELIVERY_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.req_delivery_receipt);
- _bind_stmt_field_data_int(hStmt, REQ_READ_RECEIPT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.req_read_receipt);
- _bind_stmt_field_data_int(hStmt, DOWNLOAD_LIMIT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.download_limit);
- _bind_stmt_field_data_int(hStmt, BLOCK_ADDRESS_IDX_IN_MAIL_ACCOUNT_TBL, account->options.block_address);
- _bind_stmt_field_data_int(hStmt, BLOCK_SUBJECT_IDX_IN_MAIL_ACCOUNT_TBL, account->options.block_subject);
- _bind_stmt_field_data_string(hStmt, DISPLAY_NAME_FROM_IDX_IN_MAIL_ACCOUNT_TBL, account->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
- _bind_stmt_field_data_int(hStmt, REPLY_WITH_BODY_IDX_IN_MAIL_ACCOUNT_TBL, account->options.reply_with_body);
- _bind_stmt_field_data_int(hStmt, FORWARD_WITH_FILES_IDX_IN_MAIL_ACCOUNT_TBL, account->options.forward_with_files);
- _bind_stmt_field_data_int(hStmt, ADD_MYNAME_CARD_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_myname_card);
- _bind_stmt_field_data_int(hStmt, ADD_SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_signature);
- _bind_stmt_field_data_string(hStmt, SIGNATURE_IDX_IN_MAIL_ACCOUNT_TBL, account->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
- if (account->options.add_my_address_to_bcc != 0)
- account->options.add_my_address_to_bcc = 1;
- _bind_stmt_field_data_int(hStmt, ADD_MY_ADDRESS_TO_BCC_IDX_IN_MAIL_ACCOUNT_TBL, account->options.add_my_address_to_bcc);
- _bind_stmt_field_data_int(hStmt, MY_ACCOUNT_ID_IDX_IN_MAIL_ACCOUNT_TBL, account->my_account_id);
- _bind_stmt_field_data_int(hStmt, INDEX_COLOR_IDX_IN_MAIL_ACCOUNT_TBL, account->index_color);
- _bind_stmt_field_data_int(hStmt, SYNC_STATUS_IDX_IN_MAIL_ACCOUNT_TBL, account->sync_status);
+ int i = 0;
+
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_id);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->account_name, 0, ACCOUNT_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->logo_icon_path, 0, LOGO_ICON_PATH_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_blob(hStmt, i++, account_tbl->user_data, account_tbl->user_data_length);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->user_data_length);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->account_svc_id);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_status);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->sync_disabled);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->default_mail_slot_size);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_display_name, 0, DISPLAY_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->user_email_address, 0, EMAIL_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->reply_to_address, 0, REPLY_TO_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->return_address, 0, RETURN_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_type);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_address, 0, RECEIVING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_port_number);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->incoming_server_user_name, 0, USER_NAME_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)"", 0, PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_secure_connection);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->retrieval_mode);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->keep_mails_on_pop_server_after_download);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->check_interval);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->auto_download_size);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_type);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_address, 0, SENDING_SERVER_ADDR_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_port_number);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)account_tbl->outgoing_server_user_name, 0, SENDING_USER_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char *)"", 0, SENDING_PASSWORD_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_secure_connection);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_need_authentication);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->outgoing_server_use_same_authenticator);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.priority);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.keep_local_copy);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_delivery_receipt);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.req_read_receipt);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.download_limit);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_address);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.block_subject);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.display_name_from, 0, DISPLAY_NAME_FROM_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.reply_with_body);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.forward_with_files);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_myname_card);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_signature);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->options.signature, 0, SIGNATURE_LEN_IN_MAIL_ACCOUNT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->options.add_my_address_to_bcc);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->pop_before_smtp);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->incoming_server_requires_apop);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->smime_type);
+ _bind_stmt_field_data_string(hStmt, i++, account_tbl->certificate_path, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->cipher_type);
+ _bind_stmt_field_data_int(hStmt, i++, account_tbl->digest_type);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
/* save passwords to the secure storage */
- EM_DEBUG_LOG("save to the secure storage : recv_file[%s], recv_pass[%s], send_file[%s], send_pass[%s]", recv_password_file_name, account->password, send_password_file_name, account->sending_password);
- if (ssm_write_buffer(account->password, strlen(account->password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
- EM_DEBUG_EXCEPTION("ssm_write_buffer failed - recv password : file[%s]", recv_password_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ EM_DEBUG_LOG("save to the secure storage : recv_file[%s], send_file[%s]", recv_password_file_name, send_password_file_name);
+ if ( (error_from_ssm = ssm_write_buffer(account_tbl->incoming_server_password, strlen(account_tbl->incoming_server_password), recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d] - recv password : file[%s]", error_from_ssm, recv_password_file_name);
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
- if (ssm_write_buffer(account->sending_password, strlen(account->sending_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
- EM_DEBUG_EXCEPTION("ssm_write_buffer failed - send password : file[%s]", send_password_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ if ( (error_from_ssm = ssm_write_buffer(account_tbl->outgoing_server_password, strlen(account_tbl->outgoing_server_password), send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL)) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d] - send password : file[%s]", error_from_ssm, send_password_file_name);
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
- if (!emstorage_notify_storage_event(NOTI_ACCOUNT_ADD, account->account_id, 0, NULL, 0))
- EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
ret = true;
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ if (!emstorage_notify_storage_event(NOTI_ACCOUNT_ADD, account_tbl->account_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[NOTI_ACCOUNT_ADD] : Notification failed");
FINISH_OFF:
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
- EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
else
EM_DEBUG_LOG("hStmt is NULL!!!");
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
if (err_code != NULL)
EM_DEBUG_EXCEPTION(" account_id[%d]", account_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
char send_password_file_name[MAX_PW_FILE_NAME_LENGTH];
/* get password file name */
- if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMF_ERROR_NONE) {
+ if ((error = _get_password_file_name(account_id, recv_password_file_name, send_password_file_name)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("_get_password_file_name failed.");
goto FINISH_OFF;
}
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_account_tbl WHERE account_id = %d", account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* validate account existence */
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched account found...");
- error = EMF_ERROR_ACCOUNT_NOT_FOUND;
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
goto FINISH_OFF;
}
/* delete from secure storage */
if (ssm_delete_file(recv_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
EM_DEBUG_EXCEPTION(" ssm_delete_file failed -recv password : file[%s]", recv_password_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (ssm_delete_file(send_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
EM_DEBUG_EXCEPTION(" ssm_delete_file failed -send password : file[%s]", send_password_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (count > 0) {
if (!account_list || !*account_list) {
EM_DEBUG_EXCEPTION("account_list[%p], count[%d]", account_list, count);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
for (; i < count; i++) {
EM_SAFE_FREE(p[i].account_name);
- EM_SAFE_FREE(p[i].receiving_server_addr);
- EM_SAFE_FREE(p[i].email_addr);
- EM_SAFE_FREE(p[i].user_name);
- EM_SAFE_FREE(p[i].password);
- EM_SAFE_FREE(p[i].sending_server_addr);
- EM_SAFE_FREE(p[i].sending_user);
- EM_SAFE_FREE(p[i].sending_password);
- EM_SAFE_FREE(p[i].display_name);
- EM_SAFE_FREE(p[i].reply_to_addr);
- EM_SAFE_FREE(p[i].return_addr);
+ EM_SAFE_FREE(p[i].incoming_server_address);
+ EM_SAFE_FREE(p[i].user_email_address);
+ EM_SAFE_FREE(p[i].user_data);
+ EM_SAFE_FREE(p[i].incoming_server_user_name);
+ EM_SAFE_FREE(p[i].incoming_server_password);
+ EM_SAFE_FREE(p[i].outgoing_server_address);
+ EM_SAFE_FREE(p[i].outgoing_server_user_name);
+ EM_SAFE_FREE(p[i].outgoing_server_password);
+ EM_SAFE_FREE(p[i].user_display_name);
+ EM_SAFE_FREE(p[i].reply_to_address);
+ EM_SAFE_FREE(p[i].return_address);
EM_SAFE_FREE(p[i].logo_icon_path);
EM_SAFE_FREE(p[i].options.display_name_from);
EM_SAFE_FREE(p[i].options.signature);
+ EM_SAFE_FREE(p[i].certificate_path);
}
EM_SAFE_FREE(p);
EM_DEBUG_EXCEPTION(" account_list[%d], local_yn[%d], count[%p]", account_id, local_yn, count);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_list(int account_id, int local_yn, email_mailbox_sort_type_t sort_type, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
EM_DEBUG_EXCEPTION("Invalid parameters");
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- int i = 0, rc, count = 0, ret = false, col_index;
- int error = EMF_ERROR_NONE;
- emstorage_mailbox_tbl_t* p_data_tbl = NULL;
- char **result;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
- char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_READ_TRANSACTION(transaction);
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
if (account_id == ALL_ACCOUNT) {
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl ", fields);
- if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL)
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE local_yn = %d ", local_yn);
+ if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL)
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " WHERE local_yn = %d ", local_yn);
}
else {
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d ", fields, account_id);
- if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL)
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND local_yn = %d ", local_yn);
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d ", account_id);
+ if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL)
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND local_yn = %d ", local_yn);
}
switch (sort_type) {
case EMAIL_MAILBOX_SORT_BY_NAME_ASC :
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_name ASC");
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_name ASC");
break;
case EMAIL_MAILBOX_SORT_BY_NAME_DSC :
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_name DESC");
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_name DESC");
break;
case EMAIL_MAILBOX_SORT_BY_TYPE_ASC :
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_type ASC");
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_type ASC");
break;
case EMAIL_MAILBOX_SORT_BY_TYPE_DSC :
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY mailbox_type DEC");
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY mailbox_type DEC");
break;
}
- EM_DEBUG_LOG("emstorage_get_mailbox : query[%s]", sql_query_string);
+ EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
-
- if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count))) {
- EM_DEBUG_EXCEPTION(" malloc failed...");
-
- error = EMF_ERROR_OUT_OF_MEMORY;
+ if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
-
- memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-
- col_index = 11;
-
- for (i = 0; i < count; i++) {
- _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
- _get_table_field_data_int(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
- }
-
+
ret = true;
FINISH_OFF:
- if (result)
- sqlite3_free_table(result);
-
- if (ret == true) {
- *mailbox_list = p_data_tbl;
- *select_num = count;
- EM_DEBUG_LOG("Mailbox Count [ %d]", count);
- }
- else if (p_data_tbl != NULL)
- emstorage_free_mailbox(&p_data_tbl, count, NULL);
-
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-
- error = EMF_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
if (err_code != NULL)
*err_code = error;
return ret;
}
-
-INTERNAL_FUNC int emstorage_get_mailbox_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_list_ex(int account_id, int local_yn, int with_count, int *select_num, emstorage_mailbox_tbl_t** mailbox_list, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
-
- if (!select_num || !mailbox_list) {
- EM_DEBUG_EXCEPTION("Invalid parameters");
-
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
-
- return false;
- }
- int i = 0;
- int rc;
- int count = 0;
int ret = false;
- int col_index;
- int error = EMF_ERROR_NONE;
- emstorage_mailbox_tbl_t* p_data_tbl = NULL;
- char **result;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
- char *fields = "MBT.mailbox_id, MBT.account_id, local_yn, MBT.mailbox_name, MBT.mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
- int add = 0;
- int read_count = 0;
- int total_count = 0;
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_READ_TRANSACTION(transaction);
+ int error = EMAIL_ERROR_NONE;
+ int where_clause_count = 0;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
- add = 0;
- if (with_count == 0) { /* without count */
- col_index = 11;
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl AS MBT", fields);
- if (account_id > ALL_ACCOUNT) {
- add = 1;
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d ", account_id);
- }
- }
- else { /* with read count and total count */
- col_index = 13;
- if (account_id > ALL_ACCOUNT) {
- add = 1;
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl WHERE account_id = %d GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name WHERE account_id = %d ", fields, account_id, account_id);
- }
- else {
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s, total, read FROM mail_box_tbl AS MBT LEFT OUTER JOIN (SELECT mailbox_name, count(mail_id) AS total, SUM(flags_seen_field) AS read FROM mail_tbl GROUP BY mailbox_name) AS MT ON MBT.mailbox_name = MT.mailbox_name ", fields);
- }
+ if (!select_num || !mailbox_list) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ error = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
}
- if (local_yn == EMF_MAILBOX_FROM_SERVER || local_yn == EMF_MAILBOX_FROM_LOCAL) {
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s local_yn = %d ", (add ? "WHERE" : "AND"), local_yn);
+ if (local_yn == EMAIL_MAILBOX_FROM_SERVER || local_yn == EMAIL_MAILBOX_FROM_LOCAL) {
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), "WHERE local_yn = %d ", local_yn);
+ where_clause_count++;
}
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " ORDER BY MBT.mailbox_name ");
- EM_DEBUG_LOG("query[%s]", sql_query_string);
+ if (account_id > 0) {
+ if (where_clause_count == 0) {
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " WHERE ");
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " account_id = %d ", account_id);
+ }
+ else
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " AND account_id = %d ", account_id);
+ }
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)))
-
- EM_DEBUG_LOG("result count [%d]", count);
+ SNPRINTF(conditional_clause_string + strlen(conditional_clause_string), sizeof(conditional_clause_string)-(strlen(conditional_clause_string)+1), " ORDER BY MBT.mailbox_name ");
+ EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string);
- if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 1, 1, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
-
- memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-
- for (i = 0; i < count; i++) {
- _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
- _get_table_field_data_int(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
- if (with_count == 1) {
- _get_table_field_data_int(result, &(total_count), col_index++);
- p_data_tbl[i].total_mail_count_on_local = total_count;
- _get_table_field_data_int(result, &(read_count), col_index++);
- p_data_tbl[i].unread_count = total_count - read_count; /* return unread count, NOT */
- }
- /*
- EM_DEBUG_LOG("[%d]", i);
- EM_DEBUG_LOG("p_data_tbl[%d].mailbox_id[%d]", i, p_data_tbl[i].mailbox_id);
- EM_DEBUG_LOG("p_data_tbl[%d].account_id[%d]", i, p_data_tbl[i].account_id);
- EM_DEBUG_LOG("p_data_tbl[%d].local_yn[%d]", i, p_data_tbl[i].local_yn);
- EM_DEBUG_LOG("p_data_tbl[%d].mailbox_name[%s]", i, p_data_tbl[i].mailbox_name);
- EM_DEBUG_LOG("p_data_tbl[%d].mailbox_type[%d]", i, p_data_tbl[i].mailbox_type);
- EM_DEBUG_LOG("p_data_tbl[%d].alias[%s]", i, p_data_tbl[i].alias);
- EM_DEBUG_LOG("p_data_tbl[%d].sync_with_server_yn[%d]", i, p_data_tbl[i].sync_with_server_yn);
- EM_DEBUG_LOG("p_data_tbl[%d].modifiable_yn[%d]", i, p_data_tbl[i].modifiable_yn);
- EM_DEBUG_LOG("p_data_tbl[%d].has_archived_mails[%d]", i, p_data_tbl[i].has_archived_mails);
- EM_DEBUG_LOG("p_data_tbl[%d].mail_slot_size[%d]", i, p_data_tbl[i].mail_slot_size);
- EM_DEBUG_LOG("p_data_tbl[%d].unread_count[%d]", i, p_data_tbl[i].unread_count);
- EM_DEBUG_LOG("p_data_tbl[%d].total_mail_count_on_local[%d]", i, p_data_tbl[i].total_mail_count_on_local);
- EM_DEBUG_LOG("p_data_tbl[%d].total_mail_count_on_server[%d]", i, p_data_tbl[i].total_mail_count_on_server);
- */
- }
-
ret = true;
FINISH_OFF:
- if (result)
- sqlite3_free_table(result);
-
- if (ret == true) {
- *mailbox_list = p_data_tbl;
- *select_num = count;
- EM_DEBUG_LOG("Mailbox Count [ %d]", count);
- }
- else if (p_data_tbl != NULL)
- emstorage_free_mailbox(&p_data_tbl, count, NULL);
-
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-
- error = EMF_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
if (err_code != NULL)
*err_code = error;
EM_DEBUG_EXCEPTION("account_id[%d], parent_mailbox_name[%p], select_num[%p], mailbox_list[%p]", account_id, parent_mailbox_name, select_num, mailbox_list);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- int i = 0, rc, count = 0, ret = false, col_index;
- int error = EMF_ERROR_NONE;
- emstorage_mailbox_tbl_t* p_data_tbl = NULL;
- char **result;
- char sql_query_string[QUERY_SIZE] = {0, };
- char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_READ_TRANSACTION(transaction);
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
if (parent_mailbox_name)
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND UPPER(mailbox_name) LIKE UPPER('%s/%%') ORDER BY mailbox_name", fields, account_id, parent_mailbox_name);
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND UPPER(mailbox_name) LIKE UPPER('%s/%%') ORDER BY mailbox_name", account_id, parent_mailbox_name);
else
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND (mailbox_name NOT LIKE '%%/%%') ORDER BY mailbox_name", fields, account_id);
-
- EM_DEBUG_LOG("query : %s", sql_query_string);
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND (mailbox_name NOT LIKE '%%/%%') ORDER BY mailbox_name", account_id);
+ EM_DEBUG_LOG("conditional_clause_string", conditional_clause_string);
- if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count))) {
- EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
-
- memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
- col_index = 11;
-
- for (i = 0; i < count; i++) {
- _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].local_yn), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
- _get_table_field_data_int(result, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].alias), 0, col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].sync_with_server_yn), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].modifiable_yn), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].has_archived_mails), col_index++);
- _get_table_field_data_int(result, &(p_data_tbl[i].mail_slot_size), col_index++);
- }
-
- if (result)
- sqlite3_free_table(result);
ret = true;
FINISH_OFF:
- if (ret == true) {
- *mailbox_list = p_data_tbl;
- *select_num = count;
- EM_DEBUG_LOG(" Mailbox Count [ %d] ", count);
- }
- else if (p_data_tbl != NULL)
- emstorage_free_mailbox(&p_data_tbl, count, NULL);
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
if (err_code != NULL)
*err_code = error;
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p], transaction[%d], err_code[%p]", account_id, local_yn, select_num, mailbox_list, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || !select_num || !mailbox_list) {
- EM_DEBUG_EXCEPTION("\account_id[%d], local_yn[%d], select_num[%p], mailbox_list[%p]", account_id, local_yn, select_num, mailbox_list);
+ 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;
}
- int i = 0, rc, count = 0, ret = false;
- int error = EMF_ERROR_NONE;
- emstorage_mailbox_tbl_t* p_data_tbl = NULL;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
- char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND modifiable_yn = 0 ORDER BY mailbox_name", fields, account_id);
- EM_DEBUG_LOG("sql[%s]", sql_query_string);
-
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- char **result;
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- sqlite3_free_table(result);
- if (count == 0) {
- EM_DEBUG_EXCEPTION(" no mailbox_name found...");
-
- ret = true;
- goto FINISH_OFF;
- }
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND modifiable_yn = 0 ORDER BY mailbox_name", account_id);
+ EM_DEBUG_LOG("conditional_clause_string [%s]", conditional_clause_string);
- if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t) * count))) {
- EM_DEBUG_EXCEPTION(" malloc failed...");
-
- error = EMF_ERROR_OUT_OF_MEMORY;
+ if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, mailbox_list, select_num)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
- memset(p_data_tbl, 0x00, sizeof(emstorage_mailbox_tbl_t)*count);
-
- int col_index = 0;
- for (i = 0; i < count; i++) {
- col_index = 0;
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].mailbox_id), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].local_yn), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].mailbox_name), 0, col_index++);
- _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl[i].mailbox_type), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].alias), 0, col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].sync_with_server_yn), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].modifiable_yn), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].total_mail_count_on_server), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].has_archived_mails), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].mail_slot_size), col_index++);
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
- }
-
ret = true;
FINISH_OFF:
- if (ret == true) {
- *mailbox_list = p_data_tbl;
- *select_num = count;
- EM_DEBUG_LOG("Mailbox Count[%d]", count);
- }
- else if (p_data_tbl != NULL)
- emstorage_free_mailbox(&p_data_tbl, count, NULL);
-
- if (hStmt != NULL) {
- EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
-
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
- }
- }
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
if (err_code != NULL)
*err_code = error;
return ret;
}
+INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(int input_mailbox_id, int input_transaction)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_transaction [%d]", input_mailbox_id, input_transaction);
+
+ int result_code = false;
+ int error = EMAIL_ERROR_NONE;
+ int rc;
+ time_t current_time = 0;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ sqlite3 *local_db_handle = NULL;
+
+ if (!input_mailbox_id ) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ time(¤t_time);
+
+ local_db_handle = emstorage_get_db_connection();
+
+ EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_box_tbl SET"
+ " last_sync_time = %d"
+ " WHERE mailbox_id = %d"
+ , (int)current_time
+ , input_mailbox_id);
+
+ EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+FINISH_OFF:
+
+ if(error == EMAIL_ERROR_NONE)
+ result_code = true;
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, result_code, error);
+ _DISCONNECT_DB;
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
+}
INTERNAL_FUNC int emstorage_get_mailbox_by_name(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t** result_mailbox, int transaction, int *err_code)
{
EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- int rc, ret = false;
- int error = EMF_ERROR_NONE;
- int col_index = 0;
- emstorage_mailbox_tbl_t* p_data_tbl = NULL;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
- char *fields = "mailbox_id, account_id, local_yn, mailbox_name, mailbox_type, alias, sync_with_server_yn, modifiable_yn, total_mail_count_on_server, has_archived_mails, mail_slot_size ";
- sqlite3 *local_db_handle = NULL;
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ int result_count = 0;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
- if(strcmp(mailbox_name, EMF_SEARCH_RESULT_MAILBOX_NAME) == 0) {
- if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t)))) {
+ if(strcmp(mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) == 0) {
+ if (!(*result_mailbox = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t)))) {
EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
- p_data_tbl->mailbox_id = 0;
- p_data_tbl->account_id = account_id;
- p_data_tbl->local_yn = 1;
- p_data_tbl->mailbox_name = EM_SAFE_STRDUP(mailbox_name);
- p_data_tbl->mailbox_type = EMF_MAILBOX_TYPE_SEARCH_RESULT;
- p_data_tbl->alias = EM_SAFE_STRDUP(mailbox_name);
- p_data_tbl->sync_with_server_yn = 0;
- p_data_tbl->modifiable_yn = 1;
- p_data_tbl->total_mail_count_on_server = 1;
- p_data_tbl->has_archived_mails = 0;
- p_data_tbl->mail_slot_size = 0x0FFFFFFF;
+ (*result_mailbox)->mailbox_id = 0;
+ (*result_mailbox)->account_id = account_id;
+ (*result_mailbox)->local_yn = 1;
+ (*result_mailbox)->mailbox_name = EM_SAFE_STRDUP(mailbox_name);
+ (*result_mailbox)->mailbox_type = EMAIL_MAILBOX_TYPE_SEARCH_RESULT;
+ (*result_mailbox)->alias = EM_SAFE_STRDUP(mailbox_name);
+ (*result_mailbox)->sync_with_server_yn = 0;
+ (*result_mailbox)->modifiable_yn = 1;
+ (*result_mailbox)->total_mail_count_on_server = 1;
+ (*result_mailbox)->has_archived_mails = 0;
+ (*result_mailbox)->mail_slot_size = 0x0FFFFFFF;
}
else {
- local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_READ_TRANSACTION(transaction);
if (local_yn == -1)
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND mailbox_name = '%s'", fields, account_id, mailbox_name);
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox_name);
else
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT %s FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d AND mailbox_name = '%s'", fields, account_id, local_yn, mailbox_name);
-
- EM_DEBUG_LOG("query = [%s]", sql_query_string);
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE account_id = %d AND local_yn = %d AND mailbox_name = '%s'", account_id, local_yn, mailbox_name);
+ EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- if (rc == SQLITE_DONE) {
- EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
- error = EMF_ERROR_MAILBOX_NOT_FOUND;
- goto FINISH_OFF;
- }
-
- if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)em_malloc(sizeof(emstorage_mailbox_tbl_t)))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ if( (error = emstorage_query_mailbox_tbl(conditional_clause_string, 0, transaction, result_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", error);
goto FINISH_OFF;
}
-
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->local_yn), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, col_index++);
- _get_stmt_field_data_int(hStmt, (int *)&(p_data_tbl->mailbox_type), col_index++);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->alias), 0, col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->sync_with_server_yn), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->modifiable_yn), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->total_mail_count_on_server), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->has_archived_mails), col_index++);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_slot_size), col_index++);
}
ret = true;
FINISH_OFF:
- if (ret == true)
- *result_mailbox = p_data_tbl;
- else if (p_data_tbl != NULL)
- emstorage_free_mailbox(&p_data_tbl, 1, NULL);
-
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
-
+
if (err_code != NULL)
*err_code = error;
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t** mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, emstorage_mailbox_tbl_t** mailbox_name, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
- if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
+ if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
emstorage_mailbox_tbl_t *p_data_tbl = NULL;
emstorage_account_tbl_t *account = NULL;
DB_STMT hStmt = NULL;
/* validate account */
/* Check whether the account exists. */
- if (!emstorage_get_account_by_id(account_id, EMF_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
EM_DEBUG_EXCEPTION(" emstorage_get_account_by_id failed - %d", error);
goto FINISH_OFF;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION(" no matched mailbox_name found...");
- error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
goto FINISH_OFF;
}
if (!(p_data_tbl = (emstorage_mailbox_tbl_t*)malloc(sizeof(emstorage_mailbox_tbl_t)))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailboxname_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_by_id(int input_mailbox_id, emstorage_mailbox_tbl_t** output_mailbox)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
- if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
- EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
+ EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], output_mailbox[%p]", input_mailbox_id, output_mailbox);
+
+ if (input_mailbox_id <= 0 || !output_mailbox) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ int ret = EMAIL_ERROR_NONE;
+ int result_count = 0;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
+
+ SNPRINTF(conditional_clause_string, sizeof(conditional_clause_string), "WHERE mailbox_id = %d", input_mailbox_id);
+
+ EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string);
+
+ if( (ret = emstorage_query_mailbox_tbl(conditional_clause_string, false, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", ret);
+ goto FINISH_OFF;
+ }
+
+FINISH_OFF:
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, int *mailbox_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_id[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_id, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_id) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_id[%p]", account_id, mailbox_type, mailbox_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
- char *p_mailbox = NULL;
+ int error = EMAIL_ERROR_NONE;
emstorage_account_tbl_t* account = NULL;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EMSTORAGE_START_READ_TRANSACTION(transaction);
/* Check whether the account exists. */
- if (!emstorage_get_account_by_id(account_id, EMF_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", error);
goto FINISH_OFF;
}
if (account )
emstorage_free_account(&account, 1, NULL);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_id FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
+
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ _get_stmt_field_data_int(hStmt, mailbox_id, 0);
+
+ ret = true;
+
+FINISH_OFF:
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, char **mailbox_name, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_type[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, mailbox_type, mailbox_name, transaction, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || (mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_ALL_EMAILS) || !mailbox_name) {
+ EM_DEBUG_EXCEPTION("account_id[%d], mailbox_type[%d], mailbox_name[%p]", account_id, mailbox_type, mailbox_name);
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EMAIL_ERROR_NONE;
+ emstorage_account_tbl_t* account = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+ EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+ /* Check whether the account exists. */
+ if (!emstorage_get_account_by_id(account_id, EMAIL_ACC_GET_OPT_ACCOUNT_NAME, &account, true, &error) || !account) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", error);
+ goto FINISH_OFF;
+ }
+
+ if (account )
+ emstorage_free_account(&account, 1, NULL);
+
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mailbox_name FROM mail_box_tbl WHERE account_id = %d AND mailbox_type = %d ", account_id, mailbox_type);
EM_DEBUG_LOG("query = [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no matched mailbox_name found...");
- error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
goto FINISH_OFF;
}
- _get_stmt_field_data_string(hStmt, &(p_mailbox), 0, 0);
+ _get_stmt_field_data_string(hStmt, mailbox_name, 0, 0);
ret = true;
FINISH_OFF:
- if (ret == true)
- *mailbox_name = p_mailbox;
- else
- EM_SAFE_FREE(p_mailbox);
-
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], local_yn [%d], mailbox_name [%p], modifiable_yn [%d], transaction [%d], err_code [%p]", account_id, local_yn, mailbox_name, modifiable_yn, transaction, err_code);
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
, local_yn
, mailbox_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
}
-INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, char *mailbox_name, int total_count_on_server, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox_total_count(int account_id, int input_mailbox_id, int total_count_on_server, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, mailbox_name, total_count_on_server, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], total_count_on_server[%d], transaction[%d], err_code[%p]", account_id, input_mailbox_id, total_count_on_server, transaction, err_code);
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- if (account_id <= 0 || !mailbox_name) {
- EM_DEBUG_EXCEPTION("account_id[%d], mailbox_name[%p]", account_id, mailbox_name);
+ if (account_id <= 0 || input_mailbox_id <= 0) {
+ EM_DEBUG_EXCEPTION("account_id[%d], input_mailbox_id[%d]", account_id, input_mailbox_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
sqlite3 *local_db_handle = emstorage_get_db_connection();
"UPDATE mail_box_tbl SET"
" total_mail_count_on_server = %d"
" WHERE account_id = %d"
- " AND mailbox_name = '%s'"
+ " AND mailbox_id = %d"
, total_count_on_server
, account_id
- , mailbox_name);
+ , input_mailbox_id);
EM_DEBUG_LOG("query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
}
-INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t* result_mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox(int account_id, int local_yn, int input_mailbox_id, emstorage_mailbox_tbl_t* result_mailbox, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, result_mailbox, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, result_mailbox, transaction, err_code);
- if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result_mailbox) {
- EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], result_mailbox[%p]", account_id, local_yn, mailbox_name, result_mailbox);
+ if (account_id < FIRST_ACCOUNT_ID || input_mailbox_id <= 0 || !result_mailbox) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], input_mailbox_id[%d], result_mailbox[%p]", account_id, local_yn, input_mailbox_id, result_mailbox);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
int i = 0;
", total_mail_count_on_server = ?"
" WHERE account_id = %d"
" AND local_yn = %d"
- " AND mailbox_name = '%s'"
+ " AND mailbox_id = '%d'"
, account_id
, local_yn
- , mailbox_name);
+ , input_mailbox_id);
}
else {
SNPRINTF(sql_query_string, sizeof(sql_query_string),
", mail_slot_size= ?"
", total_mail_count_on_server = ?"
" WHERE account_id = %d"
- " AND mailbox_name = '%s'"
+ " AND mailbox_id = '%d'"
, account_id
- , mailbox_name);
+ , input_mailbox_id);
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_int(hStmt, i++, result_mailbox->mailbox_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
}
-INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, emstorage_mailbox_tbl_t* target_mailbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_mailbox_type(int account_id, int local_yn, char *mailbox_name, email_mailbox_type_e new_mailbox_type, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], target_mailbox[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, target_mailbox, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%s], new_mailbox_type[%d], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, new_mailbox_type, transaction, err_code);
- if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !target_mailbox) {
- EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s], target_mailbox[%p]", account_id, local_yn, mailbox_name, target_mailbox);
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox_name) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%s]", account_id, local_yn, mailbox_name);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_DEBUG_LOG("SQL(%s)", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
- _bind_stmt_field_data_int(hStmt, i++, target_mailbox->mailbox_type);
+ _bind_stmt_field_data_int(hStmt, i++, new_mailbox_type);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (hStmt != NULL) {
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
hStmt = NULL;
}
i = 0;
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_tbl SET"
- " mailbox_id = ?"
" mailbox_type = ?"
" WHERE account_id = %d"
" AND mailbox_name = '%s'"
EM_DEBUG_LOG("SQL[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
- _bind_stmt_field_data_int(hStmt, i++, target_mailbox->mailbox_id);
- _bind_stmt_field_data_int(hStmt, i++, target_mailbox->mailbox_type);
+ _bind_stmt_field_data_int(hStmt, i++, new_mailbox_type);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
if (!mailbox_tbl) {
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0,};
char **result = NULL;
+ time_t current_time;
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
EM_SAFE_STRCPY(sql_query_string, "SELECT max(rowid) FROM mail_box_tbl;");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ time(¤t_time);
+
if (NULL == result[1])
rc = 1;
else
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"INSERT INTO mail_box_tbl VALUES "
- "( ?" /* mailbox_id */
- ", ?" /* account_id */
- ", ?" /* local_yn */
- ", ?" /* mailbox_name */
- ", ?" /* mailbox_type */
- ", ?" /* alias */
- ", ?" /* sync_with_server_yn */
- ", ?" /* modifiable_yn */
- ", ?" /* total_mail_count_on_server */
- ", ?" /* has_archived_mails */
- ", ? )");/* mail_slot_size */
+ "( ?" /* mailbox_id */
+ ", ?" /* account_id */
+ ", ?" /* local_yn */
+ ", ?" /* mailbox_name */
+ ", ?" /* mailbox_type */
+ ", ?" /* alias */
+ ", ?" /* sync_with_server_yn */
+ ", ?" /* modifiable_yn */
+ ", ?" /* total_mail_count_on_server */
+ ", ?" /* has_archived_mails */
+ ", ?" /* mail_slot_size */
+ ", ? )");/* last_sync_time */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
int col_index = 0;
_bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->total_mail_count_on_server);
_bind_stmt_field_data_int(hStmt, col_index++, 0);
_bind_stmt_field_data_int(hStmt, col_index++, mailbox_tbl->mail_slot_size);
+ _bind_stmt_field_data_int(hStmt, col_index++, current_time);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%dn", rc));
-
- if (!emstorage_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_tbl->account_id, 0, mailbox_tbl->mailbox_name, 0))
- EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+
ret = true;
FINISH_OFF:
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
+ if (error == EMAIL_ERROR_NONE && !emstorage_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_tbl->account_id, mailbox_tbl->mailbox_id, mailbox_tbl->mailbox_name, 0))
+ EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+
if (err_code != NULL)
*err_code = error;
EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0,};
sqlite3 *local_db_handle = emstorage_get_db_connection();
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET modifiable_yn = %d WHERE account_id = %d", modifiable_yn, account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
FINISH_OFF:
EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
-
+
if (err_code != NULL)
*err_code = error;
EM_DEBUG_FUNC_END("ret [%d]", ret);
}
-INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, char *mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mailbox(int account_id, int local_yn, int input_mailbox_id, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], mailbox_name[%p], transaction[%d], err_code[%p]", account_id, local_yn, mailbox_name, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], local_yn[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, local_yn, input_mailbox_id, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID) {
- EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], mailbox_name[%p]", account_id, local_yn, mailbox_name);
+ EM_DEBUG_EXCEPTION(" account_id[%d], local_yn[%d], input_mailbox_id[%d]", account_id, local_yn, input_mailbox_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
else
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_box_tbl WHERE account_id = %d AND local_yn = %d ", account_id, local_yn);
- if (mailbox_name) { /* NULL means all mailbox_name */
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(1+ strlen(sql_query_string)), "AND UPPER(mailbox_name) = UPPER('%s')", mailbox_name);
+ if (input_mailbox_id > 0) { /* 0 means all mailbox_name */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(1+ strlen(sql_query_string)), "AND mailbox_id = %d", input_mailbox_id);
}
EM_DEBUG_LOG("mailbox sql_query_string [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found...");
- error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
ret = true;
}
ret = true;
EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
+ if(error == EMAIL_ERROR_NONE) {
+ if (!emstorage_notify_storage_event(NOTI_MAILBOX_DELETE, account_id, input_mailbox_id, NULL, 0))
+ EM_DEBUG_EXCEPTION("emstorage_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed");
+ }
+
if (err_code != NULL)
*err_code = error;
EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d], err_code[%p]", mailbox_list, count, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (count > 0) {
if (!mailbox_list || !*mailbox_list) {
EM_DEBUG_EXCEPTION(" mailbox_list[%p], count[%d]", mailbox_list, count);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], count[%p], exist[%p]", account_id, mailbox_name, count);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%p], uid[%p], exist[%p]", account_id, mailbox_name , uid, exist);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_READ_TRANSACTION(transaction);
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*exist = atoi(result[1]);
if (!mail) {
EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false, temp_rule;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
*mail = (emstorage_mail_tbl_t*)malloc(sizeof(emstorage_mail_tbl_t));
if (*mail == NULL) {
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
EM_DEBUG_EXCEPTION("Memory allocation for mail failed.");
goto FINISH_OFF;
}
memset(*mail, 0x00, sizeof(emstorage_mail_tbl_t));
-
+
_get_stmt_field_data_int(hStmt, &((*mail)->account_id), ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
- _get_stmt_field_data_string(hStmt, &((*mail)->mailbox_name), 0, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _get_stmt_field_data_int(hStmt, &((*mail)->mailbox_id), LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _get_stmt_field_data_string(hStmt, &((*mail)->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_int(hStmt, &((*mail)->mail_id), LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_string(hStmt, &((*mail)->server_mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_string(hStmt, &((*mail)->server_mail_id), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, char *local_mbox, emstorage_read_mail_uid_tbl_t** read_mail_uid, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_list(int account_id, int mailbox_id, emstorage_read_mail_uid_tbl_t** read_mail_uid, int *count, int transaction, int *err_code)
{
EM_PROFILE_BEGIN(emStorageGetDownloadList);
- EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%s], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, local_mbox, read_mail_uid, count, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], read_mail_uid[%p], count[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, read_mail_uid, count, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid || !count) {
- EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%s], read_mail_uid[%p], count[%p]", account_id, local_mbox, read_mail_uid, count);
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%s], read_mail_uid[%p], count[%p]", account_id, mailbox_id, read_mail_uid, count);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_READ_TRANSACTION(transaction);
- if (local_mbox)
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d AND UPPER(local_mbox) = UPPER('%s')", account_id, local_mbox);
+ if (mailbox_id)
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_id = %d", account_id, mailbox_id);
else
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_read_mail_uid_tbl WHERE account_id = %d", account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
char **result;
/* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL); */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
sqlite3_free_table(result);
if (!(p_data_tbl = (emstorage_read_mail_uid_tbl_t*)malloc(sizeof(emstorage_read_mail_uid_tbl_t) * *count))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
for (i = 0; i < *count; ++i) {
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].local_mbox), 0, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].mailbox_id),LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].local_uid), LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl[i].s_uid), 0, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag), FLAG_IDX_IN_MAIL_READ_MAIL_UID_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
}
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_downloaded_mail_size(int account_id, char *mailbox_id, int local_uid, char *mailbox_name, char *uid, int *mail_size, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, mail_size, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || !mail_size) {
- EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, mail_size);
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%p], locacal_uid[%d], mailbox_name[%p], uid[%p], mail_size[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, mail_size);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl "
"WHERE account_id = %d "
- "AND local_mbox = '%s' "
+ "AND mailbox_id = '%s' "
"AND local_uid = %d "
"AND mailbox_name = '%s' "
"AND s_uid = '%s'",
- account_id, local_mbox, local_uid, mailbox_name, uid);
+ account_id, mailbox_id, local_uid, mailbox_name, uid);
}
else {
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl "
"WHERE account_id = %d "
- "AND local_mbox = '%s' "
+ "AND mailbox_id = '%s' "
"AND local_uid = %d "
"AND s_uid = '%s'",
- account_id, local_mbox, local_uid, uid);
+ account_id, mailbox_id, local_uid, uid);
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION(" no matched mail found....");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
if (!read_mail_uid) {
EM_DEBUG_EXCEPTION("read_mail_uid[%p]", read_mail_uid);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, rc2, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL==result[1]) rc = 1;
EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
goto FINISH_OFF;
}
EM_DEBUG_LOG("account_id VALUE [%d] ", read_mail_uid->account_id);
- EM_DEBUG_LOG("local_mbox VALUE [%s] ", read_mail_uid->local_mbox);
+ EM_DEBUG_LOG("mailbox_id VALUE [%d] ", read_mail_uid->mailbox_id);
EM_DEBUG_LOG("local_uid VALUE [%d] ", read_mail_uid->local_uid);
EM_DEBUG_LOG("mailbox_name VALUE [%s] ", read_mail_uid->mailbox_name);
EM_DEBUG_LOG("s_uid VALUE [%s] ", read_mail_uid->s_uid);
EM_DEBUG_LOG("rc VALUE [%d] ", rc);
_bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->account_id);
- _bind_stmt_field_data_string(hStmt, LOCAL_MBOX_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_int(hStmt, LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->mailbox_id);
_bind_stmt_field_data_int(hStmt, LOCAL_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->local_uid);
_bind_stmt_field_data_string(hStmt, MAILBOX_NAME_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
_bind_stmt_field_data_string(hStmt, S_UID_IDX_IN_MAIL_READ_MAIL_UID_TBL, (char *)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, char *local_mbox, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_read_mail_uid(int account_id, int mailbox_id, int local_uid, char *mailbox_name, char *uid, emstorage_read_mail_uid_tbl_t* read_mail_uid, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], local_mbox[%p], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p], transaction[%d], err_code[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid, transaction, err_code);
if (account_id < FIRST_ACCOUNT_ID || !read_mail_uid) {
- EM_DEBUG_EXCEPTION(" account_id[%d], local_mbox[%p], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p]", account_id, local_mbox, local_uid, mailbox_name, uid, read_mail_uid);
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_id[%d], local_uid[%d], mailbox_name[%p], uid[%p], read_mail_uid[%p]", account_id, mailbox_id, local_uid, mailbox_name, uid, read_mail_uid);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
SNPRINTF(sql_query_string, sizeof(sql_query_string),
"UPDATE mail_read_mail_uid_tbl SET"
" account_id = ?"
- ", local_mbox = ?"
+ ", mailbox_id = ?"
", local_uid = ?"
", mailbox_name = ?"
", s_uid = ?"
", data2 = ?"
", flag = ?"
" WHERE account_id = ?"
- " AND local_mbox = ?"
+ " AND mailbox_id = ?"
" AND local_uid = ?"
" AND mailbox_name= ?"
" AND s_uid = ?");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
int i = 0;
_bind_stmt_field_data_int(hStmt, i++, read_mail_uid->account_id);
- _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, read_mail_uid->mailbox_id);
_bind_stmt_field_data_int(hStmt, i++, read_mail_uid->local_uid);
- _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char*)read_mail_uid->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char*)read_mail_uid->s_uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
_bind_stmt_field_data_int(hStmt, i++, read_mail_uid->data1);
- _bind_stmt_field_data_string(hStmt, i++, (char *)read_mail_uid->data2, 0, DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char*)read_mail_uid->data2, 0, DATA2_LEN_IN_MAIL_READ_MAIL_UID_TBL);
_bind_stmt_field_data_int(hStmt, i++, read_mail_uid->flag);
_bind_stmt_field_data_int(hStmt, i++, account_id);
- _bind_stmt_field_data_string(hStmt, i++, (char *)local_mbox, 0, LOCAL_MBOX_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, mailbox_id);
_bind_stmt_field_data_int(hStmt, i++, local_uid);
- _bind_stmt_field_data_string(hStmt, i++, (char *)mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
- _bind_stmt_field_data_string(hStmt, i++, (char *)uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char*)mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL);
+ _bind_stmt_field_data_string(hStmt, i++, (char*)uid, 0, S_UID_LEN_IN_MAIL_READ_MAIL_UID_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" account_id[%d], mailbox_name[%s], uid[%s]", account_id, mailbox_name, uid);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_FUNC_BEGIN("read_mail_uid[%p], count[%d], err_code[%p]", read_mail_uid, count, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (count > 0) {
if (!read_mail_uid || !*read_mail_uid) {
EM_DEBUG_EXCEPTION(" read_mail_uid[%p], count[%d]", read_mail_uid, count);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
int i;
for (i = 0; i < count; i++) {
- EM_SAFE_FREE(p[i].local_mbox);
EM_SAFE_FREE(p[i].mailbox_name);
EM_SAFE_FREE(p[i].s_uid);
EM_SAFE_FREE(p[i].data2);
EM_DEBUG_EXCEPTION(" account_id[%d], count[%p]", account_id, count);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
EM_DEBUG_EXCEPTION(" account_id[%d], type[%d], start_idx[%d], select_num[%p], is_completed[%p], rule_list[%p]", account_id, type, start_idx, select_num, is_completed, rule_list);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
emstorage_rule_tbl_t* p_data_tbl = NULL;
int i = 0, count = 0;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
char **result;
/* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
sqlite3_free_table(result);
if (!(p_data_tbl = (emstorage_rule_tbl_t*)malloc(sizeof(emstorage_rule_tbl_t) * count))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].type), TYPE_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl[i].value), 0, VALUE_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].action_type), ACTION_TYPE_IDX_IN_MAIL_RULE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].dest_mailbox), 0, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].target_mailbox_id), TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag1), FLAG1_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl[i].flag2), FLAG2_IDX_IN_MAIL_RULE_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], rule[%p]", account_id, rule_id, rule);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
emstorage_rule_tbl_t* p_data_tbl = NULL;
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION(" no matched rule found...");
- error = EMF_ERROR_FILTER_NOT_FOUND;
+ error = EMAIL_ERROR_FILTER_NOT_FOUND;
goto FINISH_OFF;
}
if (!(p_data_tbl = (emstorage_rule_tbl_t*)malloc(sizeof(emstorage_rule_tbl_t)))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
_get_stmt_field_data_int(hStmt, &(p_data_tbl->type), TYPE_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->value), 0, VALUE_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->action_type), ACTION_TYPE_IDX_IN_MAIL_RULE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->dest_mailbox), 0, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->target_mailbox_id), TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->flag1), FLAG1_IDX_IN_MAIL_RULE_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->flag2), FLAG2_IDX_IN_MAIL_RULE_TBL);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d], new_rule[%p]", account_id, rule_id, new_rule);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
" type = ?"
", value = ?"
", action_type = ?"
- ", dest_mailbox = ?"
+ ", target_mailbox_id = ?"
", flag1 = ?"
", flag2 = ?"
" WHERE account_id = ?"
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
int i = 0;
_bind_stmt_field_data_int(hStmt, i++, new_rule->type);
_bind_stmt_field_data_string(hStmt, i++, (char *)new_rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
_bind_stmt_field_data_int(hStmt, i++, new_rule->action_type);
- _bind_stmt_field_data_string(hStmt, i++, (char *)new_rule->dest_mailbox, 0, DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, new_rule->target_mailbox_id);
_bind_stmt_field_data_int(hStmt, i++, new_rule->flag1);
_bind_stmt_field_data_int(hStmt, i++, new_rule->flag2);
_bind_stmt_field_data_int(hStmt, i++, account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc, ret = false;
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION(" no matched rule found...");
- error = EMF_ERROR_FILTER_NOT_FOUND;
+ error = EMAIL_ERROR_FILTER_NOT_FOUND;
goto FINISH_OFF;
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" rule->account_id[%d]", rule->account_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, rc_2, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
sql = "SELECT max(rowid) FROM mail_rule_tbl;";
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL==result[1])
", ?" /* type */
", ?" /* value */
", ?" /* action_type */
- ", ?" /* dest_mailbox */
+ ", ?" /* target_mailbox_id */
", ?" /* flag1 */
", ?)"); /* flag2 */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc_2);
if (rc_2 != SQLITE_OK) {
EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc_2, sqlite3_errmsg(local_db_handle));
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
goto FINISH_OFF;
}
_bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_RULE_TBL, rule->account_id);
_bind_stmt_field_data_int(hStmt, RULE_ID_IDX_IN_MAIL_RULE_TBL, rc);
_bind_stmt_field_data_int(hStmt, TYPE_IDX_IN_MAIL_RULE_TBL, rule->type);
- _bind_stmt_field_data_string(hStmt, VALUE_IDX_IN_MAIL_RULE_TBL, (char *)rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
+ _bind_stmt_field_data_string(hStmt, VALUE_IDX_IN_MAIL_RULE_TBL, (char*)rule->value, 0, VALUE_LEN_IN_MAIL_RULE_TBL);
_bind_stmt_field_data_int(hStmt, ACTION_TYPE_IDX_IN_MAIL_RULE_TBL, rule->action_type);
- _bind_stmt_field_data_string(hStmt, DEST_MAILBOX_IDX_IN_MAIL_RULE_TBL, (char *)rule->dest_mailbox, 0, DEST_MAILBOX_LEN_IN_MAIL_RULE_TBL);
+ _bind_stmt_field_data_int(hStmt, TARGET_MAILBOX_ID_IDX_IN_MAIL_RULE_TBL, rule->target_mailbox_id);
_bind_stmt_field_data_int(hStmt, FLAG1_IDX_IN_MAIL_RULE_TBL, rule->flag1);
_bind_stmt_field_data_int(hStmt, FLAG2_IDX_IN_MAIL_RULE_TBL, rule->flag2);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" account_id[%d], rule_id[%d]", account_id, rule_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_rule_tbl WHERE account_id = %d AND rule_id = %d", account_id, rule_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched rule found...");
- error = EMF_ERROR_FILTER_NOT_FOUND;
+ error = EMAIL_ERROR_FILTER_NOT_FOUND;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN("rule_list[%p], conut[%d], err_code[%p]", rule_list, count, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (count > 0) {
if (!rule_list || !*rule_list) {
EM_DEBUG_EXCEPTION(" rule_list[%p], conut[%d]", rule_list, count);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
for (; i < count; i++) {
EM_SAFE_FREE(p[i].value);
- EM_SAFE_FREE(p[i].dest_mailbox);
}
EM_SAFE_FREE(p); *rule_list = NULL;
if (!total && !unseen) {
EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p], unseen[%p]", account_id, mailbox_name, total, unseen);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
char err_msg[1024];
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF2; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF2; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*total = atoi(result[1]);
#else
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF2; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF2; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF2; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF2; },
("sqlite3_step fail:%d", rc));
_get_stmt_field_data_int(hStmt, total, 0);
#endif /* USE_GET_RECORD_COUNT_API */
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*unseen = atoi(result[1]);
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" EDBStmtClearRow failed - %d: %s", rc, err_msg);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
#endif
if (mail_id <= 0 || !mail) {
EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
if (p_data_tbl == NULL) {
EM_DEBUG_EXCEPTION("malloc failed...");
if (err_code != NULL)
- *err_code = EMF_ERROR_OUT_OF_MEMORY;
+ *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
return false;
}
char sql_query_string[QUERY_SIZE] = {0, };
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_READ_TRANSACTION(transaction);
switch (type) {
case RETRIEVE_SUMMARY:
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id, mail_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id);
+ "SELECT account_id, mail_id, mailbox_id, mailbox_name, server_mail_status, server_mailbox_name, server_mail_id, file_path_plain, file_path_html, flags_seen_field, save_status, lock_status, thread_id, thread_item_count FROM mail_tbl WHERE mail_id = %d", mail_id);
break;
case RETRIEVE_FIELDS_FOR_DELETE:
case RETRIEVE_FLAG:
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id, mailbox_name, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id = %d", mail_id);
+ "SELECT account_id, mailbox_name, flags_seen_field, thread_id, mailbox_id FROM mail_tbl WHERE mail_id = %d", mail_id);
break;
default :
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM : type [%d]", type);
- error = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type);
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
switch (type) {
case RETRIEVE_SUMMARY:
_get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), 0);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), 1);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, 2);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), 3);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, 4);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, 5);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, 6);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, 7);
- _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), 8);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->save_status), 9);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), 10);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 11);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), 12);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), 2);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, 3);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), 4);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, 5);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, 6);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, 7);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, 8);
+ _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), 9);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->save_status), 10);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), 11);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 12);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), 13);
break;
case RETRIEVE_FIELDS_FOR_DELETE:
_get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, 1);
_get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), 2);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), 3);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), 4);
break;
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_ids, number_of_mails, type, mail, transaction, err_code);
if (number_of_mails <= 0 || !mail_ids) {
- EM_DEBUG_EXCEPTION("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;
}
if (p_data_tbl == NULL) {
EM_DEBUG_EXCEPTION("malloc failed...");
if (err_code != NULL)
- *err_code = EMF_ERROR_OUT_OF_MEMORY;
+ *err_code = EMAIL_ERROR_OUT_OF_MEMORY;
return false;
}
DB_STMT hStmt = NULL;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int i = 0, item_count = 0, rc = -1, field_count, col_index, cur_sql_query_string = 0;
char **result = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
case RETRIEVE_FLAG:
cur_sql_query_string = SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "SELECT account_id, mailbox_name, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in (");
+ "SELECT account_id, mailbox_id, flags_seen_field, thread_id FROM mail_tbl WHERE mail_id in (");
field_count = 4;
break;
default :
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM : type [%d]", type);
- error = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type);
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EM_DEBUG_LOG("Query [%s], Length [%d]", sql_query_string, strlen(sql_query_string));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &item_count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
if(number_of_mails != item_count) {
EM_DEBUG_EXCEPTION("Can't find all emails");
- /* error = EMF_ERROR_MAIL_NOT_FOUND;
+ /* error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF; */ /* removed temporarily */
}
case RETRIEVE_FLAG:
_get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++);
- _get_table_field_data_string(result, &(p_data_tbl[i].mailbox_name), 0, col_index++);
+ _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++);
_get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++);
_get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++);
break;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
if (mail_id <= 0 || !mail) {
EM_DEBUG_EXCEPTION("mail_id[%d], mail[%p]", mail_id, mail);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- int ret = false, error = EMF_ERROR_NONE, count;
+ int ret = false, error = EMAIL_ERROR_NONE, count;
char conditional_clause[QUERY_SIZE] = {0, };
emstorage_mail_tbl_t* p_data_tbl = NULL;
if (!search_handle || !searched) {
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
EM_DEBUG_FUNC_END("false");
return false;
}
emstorage_search_filter_t* p = search;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
int rc, ret = false;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &mail_count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
sqlite3_free_table(result);
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" search_handle[%d], type[%d], data[%p]", search_handle, type, data);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
emstorage_mail_tbl_t* p_data_tbl = NULL;
DB_STMT hStmt = (DB_STMT)search_handle;
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
switch (type) {
case RETRIEVE_ID:
if (!(p_data_tbl = em_malloc(sizeof(emstorage_mail_tbl_t)))) {
EM_DEBUG_EXCEPTION(" em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
_get_stmt_field_data_int (hStmt, &(p_data_tbl->body_download_status), BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL);
_get_stmt_field_data_time_t(hStmt, &(p_data_tbl->date_time), DATETIME_IDX_IN_MAIL_TBL);
_get_stmt_field_data_char (hStmt, &(p_data_tbl->flags_seen_field), FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl->DRM_status), DRM_STATUS_IDX_IN_MAIL_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl->report_status), REPORT_STATUS_IDX_IN_MAIL_TBL);
_get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl->meeting_request_status), MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL);
+ _get_stmt_field_data_int (hStmt, &(p_data_tbl->message_class), MESSAGE_CLASS_IDX_IN_MAIL_TBL);
+ _get_stmt_field_data_int (hStmt, &(p_data_tbl->digest_type), DIGEST_TYPE_IDX_IN_MAIL_TBL);
+ _get_stmt_field_data_int (hStmt, &(p_data_tbl->smime_type), SMIME_TYPE_IDX_IN_MAIL_TBL);
if (type == RETRIEVE_ALL) {
_get_stmt_field_data_int (hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL);
if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
case RETRIEVE_ADDRESS:
if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
{
EM_DEBUG_FUNC_BEGIN("search_handle[%d], transaction[%d], err_code[%p]", search_handle, transaction, err_code);
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc, ret = false;
if (search_handle < 0) {
EM_DEBUG_EXCEPTION(" search_handle[%d]", search_handle);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
ret = true;
EM_DEBUG_EXCEPTION(" mail_id[%d], mail[%p]", mail_id, mail);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
char sql_query_string[QUERY_SIZE] = {0, };
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int i = 0;
sqlite3 *local_db_handle = emstorage_get_db_connection();
+ char mailbox_id_param_string[10] = {0,};
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
", message_id = ?"
", report_status = ?"
", preview_text = ?"
+ ", smime_type = ?"
" WHERE mail_id = %d AND account_id != 0 "
, mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_int (hStmt, i++, mail->mail_id);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->message_id, 0, MESSAGE_ID_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int (hStmt, i++, mail->report_status);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
+ _bind_stmt_field_data_int (hStmt, i++, mail->smime_type);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
-
- if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail->mail_id, mail->mailbox_name, 0))
+ SNPRINTF(mailbox_id_param_string, 10, "%d", mail->mailbox_id);
+ if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail->mail_id, mailbox_id_param_string, 0))
EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" old_mailbox_name[%p], new_mailbox_name[%p]", old_mailbox_name, new_mailbox_name);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s' WHERE mailbox_name = '%s'", new_mailbox_name, old_mailbox_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
EM_IF_NULL_RETURN_VALUE(err_code, false);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc = 0;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
memset(sql_query_string, 0x00, sizeof(sql_query_string));
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMF_MAIL_STATUS_SENDING);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET save_status = %d WHERE save_status = %d", save_status, EMAIL_MAIL_STATUS_SENDING);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_LOG(" No Matched Mail Exists ");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
}
ret = true;
INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(int account_id, int mail_ids[], int mail_ids_count, char *field_name, int value, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], mail_ids_count[%d], field_name[%s], value[%d], transaction[%d], err_code[%p]", account_id, mail_ids, mail_ids_count, field_name, value, transaction, err_code);
- int i, error, rc, ret = false, cur_mail_id_string = 0, mail_id_string_buffer_length = 0;
- char sql_query_string[QUERY_SIZE] = {0, }, *mail_id_string_buffer = NULL, *parameter_string = NULL;
+ int i = 0;
+ int error = EMAIL_ERROR_NONE;
+ int rc = 0;
+ int ret = false;
+ int cur_mail_id_string = 0;
+ int mail_id_string_buffer_length = 0;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *mail_id_string_buffer = NULL;
+ char *parameter_string = NULL;
sqlite3 *local_db_handle = emstorage_get_db_connection();
+ email_mail_attribute_type target_mail_attribute_type = 0;
if (!mail_ids || !field_name || account_id == 0) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ if( (error = _get_attribute_type_by_mail_field_name(field_name, &target_mail_attribute_type)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_get_attribute_type_by_mail_field_name failed [%d]", error);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = error;
return false;
}
if(!mail_id_string_buffer) {
EM_DEBUG_EXCEPTION("em_malloc failed");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
if(!parameter_string) {
EM_DEBUG_EXCEPTION("em_malloc failed");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
/* Write query string */
SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET %s = %d WHERE mail_id in (%s) AND account_id = %d", field_name, value, mail_id_string_buffer, account_id);
+ EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
+
/* Execute query */
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (sqlite3_changes(local_db_handle) == 0)
EM_DEBUG_LOG("no mail matched...");
EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
- if (ret && parameter_string && !emstorage_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, 0, parameter_string, value))
- EM_DEBUG_EXCEPTION("emstorage_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", field_name, value);
+ if (ret && parameter_string && !emstorage_notify_storage_event(NOTI_MAIL_FIELD_UPDATE, account_id, target_mail_attribute_type, parameter_string, value))
+ EM_DEBUG_EXCEPTION("emstorage_notify_storage_event failed : NOTI_MAIL_FIELD_UPDATE [%s,%d]", field_name, value);
EM_SAFE_FREE(mail_id_string_buffer);
EM_SAFE_FREE(parameter_string);
if (err_code != NULL)
*err_code = error;
- EM_DEBUG_FUNC_END("ret [%d]", ret);
+ EM_DEBUG_FUNC_END("error [%d]", error);
return ret;
}
-INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, emf_mail_change_type_t type, emstorage_mail_tbl_t* mail, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_mail_field(int mail_id, email_mail_change_type_t type, emstorage_mail_tbl_t* mail, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], mail[%p], transaction[%d], err_code[%p]", mail_id, type, mail, transaction, err_code);
if (mail_id <= 0 || !mail) {
EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], mail[%p]", mail_id, type, mail);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int move_flag = 0;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
int rc = 0;
int i = 0;
- char *mailbox_name = NULL;
+ char *mailbox_name = NULL;
+ char mailbox_id_param_string[10] = {0,};
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
", attachment_count = ?"
", preview_text= ?"
", meeting_request_status = ? "
+ ", message_class = ? "
+ ", digest_type = ? "
+ ", smime_type = ? "
" WHERE mail_id = %d AND account_id != 0"
, mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
i = 0;
_bind_stmt_field_data_int(hStmt, i++, mail->attachment_count);
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int(hStmt, i++, mail->meeting_request_status);
+ _bind_stmt_field_data_int(hStmt, i++, mail->message_class);
+ _bind_stmt_field_data_int(hStmt, i++, mail->digest_type);
+ _bind_stmt_field_data_int(hStmt, i++, mail->smime_type);
break;
case UPDATE_MAILBOX: {
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
}
break;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
break;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
break;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
break;
", attachment_count = ?"
", inline_content_count = ?"
", meeting_request_status = ?"
+ ", message_class = ?"
+ ", digest_type = ?"
+ ", smime_type = ?"
" WHERE mail_id = %d AND account_id != 0"
, mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
i = 0;
_bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int (hStmt, i++, mail->attachment_count);
_bind_stmt_field_data_int (hStmt, i++, mail->inline_content_count);
_bind_stmt_field_data_int (hStmt, i++, mail->meeting_request_status);
+ _bind_stmt_field_data_int (hStmt, i++, mail->message_class);
+ _bind_stmt_field_data_int (hStmt, i++, mail->digest_type);
+ _bind_stmt_field_data_int (hStmt, i++, mail->smime_type);
break;
case UPDATE_DATETIME: {
, mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
break;
}
hStmt = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
i = 0;
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
hStmt = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
i = 0;
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
hStmt = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
i = 0;
_bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
i = 0;
default:
EM_DEBUG_LOG(" type[%d]", type);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if (hStmt != NULL) {
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
}
if (mail->account_id == 0) {
- emstorage_mail_tbl_t* mail_for_account = NULL;
- if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_ACCOUNT, &mail_for_account, true, &error) || !mail_for_account) {
+ emstorage_mail_tbl_t* mail_for_account_tbl = NULL;
+ if (!emstorage_get_mail_field_by_id(mail_id, RETRIEVE_ACCOUNT, &mail_for_account_tbl, true, &error) || !mail_for_account_tbl) {
EM_DEBUG_EXCEPTION(" emstorage_get_mail_field_by_id failed - %d", error);
/* */
goto FINISH_OFF;
}
- mail->account_id = mail_for_account->account_id;
- if (mail_for_account)
- emstorage_free_mail(&mail_for_account, 1, NULL);
+ mail->account_id = mail_for_account_tbl->account_id;
+ if (mail_for_account_tbl)
+ emstorage_free_mail(&mail_for_account_tbl, 1, NULL);
}
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
hStmt = NULL;
}
/*h.gahlaut@samsung.com: Moving publication of notification after commiting transaction to DB */
if (ret == true && move_flag != 1) {
- if (!emstorage_get_mailboxname_by_mailbox_type(mail->account_id, EMF_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &error))
- EM_DEBUG_EXCEPTION(" emstorage_get_mailboxname_by_mailbox_type failed - %d", error);
+ if (!emstorage_get_mailbox_name_by_mailbox_type(mail->account_id, EMAIL_MAILBOX_TYPE_SENTBOX, &mailbox_name, false, &error))
+ EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_name_by_mailbox_type failed - %d", error);
if (mail->mailbox_name && mailbox_name) {
if (strcmp(mail->mailbox_name, mailbox_name) != 0) {
- if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, mail->mailbox_name, type))
+ SNPRINTF(mailbox_id_param_string, 10, "%d", mail->mailbox_id);
+ if (!emstorage_notify_storage_event(NOTI_MAIL_UPDATE, mail->account_id, mail_id, mailbox_id_param_string, type))
EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAIL_UPDATE ] >>>> ");
}
}
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-
-
-INTERNAL_FUNC int emstorage_get_mail_count_with_draft_flag(int account_id, const char *mailbox_name, int *total, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, transaction, err_code);
-
- if (!total) {
- EM_DEBUG_EXCEPTION("accoun_id[%d], mailbox_name[%s], total[%p]", account_id, mailbox_name, total);
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;
- }
+ EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
- int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
-
- memset(&sql_query_string, 0x00, sizeof(sql_query_string));
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- if (total) {
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_draft_field = 1");
-
- if (account_id != ALL_ACCOUNT)
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
-
- if (mailbox_name)
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
-
-#ifdef USE_GET_RECORD_COUNT_API
- EM_DEBUG_LOG("Query : [%s]", sql_query_string);
- char **result;
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- *total = atoi(result[1]);
- sqlite3_free_table(result);
-#else
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- _get_stmt_field_data_int(hStmt, total, 0);
-#endif /* USE_GET_RECORD_COUNT_API */
- }
- ret = true;
-
-FINISH_OFF:
-#ifndef USE_GET_RECORD_COUNT_API
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
- }
- }
-#endif
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_get_mail_count_on_sending(int account_id, const char *mailbox_name, int *total, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], total[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, total, transaction, err_code);
-
- if (!total) {
- EM_DEBUG_EXCEPTION(" accoun_id[%d], mailbox_name[%s], total[%p]", account_id, mailbox_name, total);
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;
- }
-
- int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
-
- memset(&sql_query_string, 0x00, sizeof(sql_query_string));
- sqlite3 *local_db_handle = emstorage_get_db_connection();
- EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- if (total) {
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE save_status = %d ", EMF_MAIL_STATUS_SENDING);
-
- if (account_id != ALL_ACCOUNT)
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND account_id = %d", account_id);
-
- if (mailbox_name)
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND mailbox_name = '%s'", mailbox_name);
-
-#ifdef USE_GET_RECORD_COUNT_API
- char **result;
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- *total = atoi(result[1]);
- sqlite3_free_table(result);
-#else
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- _get_stmt_field_data_int(hStmt, total, 0);
-#endif /* USE_GET_RECORD_COUNT_API */
- }
- ret = true;
-
-FINISH_OFF:
-#ifndef USE_GET_RECORD_COUNT_API
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
-
- error = EMF_ERROR_DB_FAILURE;
- }
- }
-#endif
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
- _DISCONNECT_DB;
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-
-}
-
-INTERNAL_FUNC int emstorage_increase_mail_id(int *mail_id, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("mail_id[%p], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
-
- int rc, ret = false;
- int error = EMF_ERROR_NONE;
- int latest_mail_id = 0;
- sqlite3 *local_db_handle = NULL;
- char *sql = "SELECT MAX(mail_id) FROM mail_tbl;";
- char **result = NULL;
+ int rc, ret = false;
+ int error = EMAIL_ERROR_NONE;
+ int latest_mail_id = 0;
+ sqlite3 *local_db_handle = NULL;
+ char *sql = "SELECT MAX(mail_id) FROM mail_tbl;";
+ char **result = NULL;
#ifdef __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__
_timedlock_shm_mutex(&mapped_for_generating_mail_id, 2);
local_db_handle = emstorage_get_db_connection();
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL == result[1])
rc = 1;
if (!mail_tbl_data) {
EM_DEBUG_EXCEPTION("mail_tbl_data[%p], get_id[%d]", mail_tbl_data, get_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
sqlite3 *local_db_handle = emstorage_get_db_connection();
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL == result[1])
", ?" /* body_download_status */
", ?" /* file_path_plain */
", ?" /* file_path_html */
+ ", ?" /* file_path_mime_entity */
", ?" /* mail_size */
", ?" /* flags_seen_field */
", ?" /* flags_deleted_field */
", ?" /* thread_item_count */
", ?" /* preview_text */
", ?" /* meeting_request_status */
+ ", ?" /* message_class */
+ ", ?" /* digest_type */
+ ", ?" /* smime_type */
")");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_int (hStmt, MAIL_ID_IDX_IN_MAIL_TBL, mail_tbl_data->mail_id);
_bind_stmt_field_data_int (hStmt, BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->body_download_status);
_bind_stmt_field_data_string(hStmt, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_string(hStmt, FILE_PATH_HTML_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL);
+ _bind_stmt_field_data_string(hStmt, FILE_PATH_MIME_ENTITY_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int (hStmt, MAIL_SIZE_IDX_IN_MAIL_TBL, mail_tbl_data->mail_size);
_bind_stmt_field_data_int (hStmt, FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_seen_field);
_bind_stmt_field_data_int (hStmt, FLAGS_DELETED_FIELD_IDX_IN_MAIL_TBL, mail_tbl_data->flags_deleted_field);
_bind_stmt_field_data_int (hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, mail_tbl_data->thread_item_count);
_bind_stmt_field_data_string(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, (char*)mail_tbl_data->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int (hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, mail_tbl_data->meeting_request_status);
+ _bind_stmt_field_data_int (hStmt, MESSAGE_CLASS_IDX_IN_MAIL_TBL, mail_tbl_data->message_class);
+ _bind_stmt_field_data_int (hStmt, DIGEST_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->digest_type);
+ _bind_stmt_field_data_int (hStmt, SMIME_TYPE_IDX_IN_MAIL_TBL, mail_tbl_data->smime_type);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
ret = true;
FINISH_OFF:
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG("sqlite3_finalize failed [%d]", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, char *target_mailbox_name, int mail_ids[], int number_of_mails, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_move_multiple_mails(int account_id, int input_mailbox_id, int mail_ids[], int number_of_mails, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id [%d], target_mailbox_name [%s], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", account_id, target_mailbox_name, mail_ids, number_of_mails, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], input_mailbox_id [%d], mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", account_id, input_mailbox_id, mail_ids, number_of_mails, transaction, err_code);
int rc, ret = false, i, cur_conditional_clause = 0;
- int error = EMF_ERROR_NONE;
- int target_mailbox_id = 0;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, }, conditional_clause[QUERY_SIZE] = {0, };
emstorage_mailbox_tbl_t *result_mailbox = NULL;
- emf_mailbox_type_e target_mailbox_type = EMF_MAILBOX_TYPE_USER_DEFINED;
+ email_mailbox_type_e target_mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED;
+ char* target_mailbox_name = NULL;
- if (!mail_ids || !target_mailbox_name) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ if (!mail_ids || input_mailbox_id <= 0) {
+ 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;
}
sqlite3 *local_db_handle = emstorage_get_db_connection();
- if(!emstorage_get_mailbox_by_name(account_id, -1, target_mailbox_name, &result_mailbox, true, &error)) {
- EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_name failed [%d]", error);
+ if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &result_mailbox)) != EMAIL_ERROR_NONE || !result_mailbox) {
+ EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", error);
goto FINISH_OFF;
}
if(result_mailbox) {
+ target_mailbox_name = EM_SAFE_STRDUP(result_mailbox->mailbox_name);
target_mailbox_type = result_mailbox->mailbox_type;
- target_mailbox_id = result_mailbox->mailbox_id;
emstorage_free_mailbox(&result_mailbox, 1, NULL);
}
/* Updating a mail_tbl */
memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_name = '%s', mailbox_type = %d, mailbox_id = %d %s", target_mailbox_name, target_mailbox_type, target_mailbox_id, conditional_clause);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_tbl SET mailbox_name = '%s', mailbox_type = %d, mailbox_id = %d %s", target_mailbox_name, target_mailbox_type, input_mailbox_id, conditional_clause);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
/* Updating a mail_attachment_tbl */
memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_name = '%s' %s", target_mailbox_name, conditional_clause);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_attachment_tbl SET mailbox_id = '%d' %s", input_mailbox_id, conditional_clause);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
/* Updating a mail_meeting_tbl */
memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_name = '%s' %s", target_mailbox_name, conditional_clause);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_meeting_tbl SET mailbox_id = %d %s", input_mailbox_id, conditional_clause);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
conditional_clause[strlen(conditional_clause) - 1] = ')';
memset(sql_query_string, 0x00, QUERY_SIZE);
- SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', local_mbox = '%s' %s", target_mailbox_name, target_mailbox_name, conditional_clause);
+ SNPRINTF(sql_query_string, QUERY_SIZE, "UPDATE mail_read_mail_uid_tbl SET mailbox_name = '%s', mailbox_id = %d %s", target_mailbox_name, input_mailbox_id, conditional_clause);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
+ EM_SAFE_FREE(target_mailbox_name);
+
if (err_code != NULL)
*err_code = error;
if (!mail_id) {
EM_DEBUG_EXCEPTION("mail_id[%d]", mail_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_DEBUG_FUNC_BEGIN("mail_ids[%p], number_of_mails [%d], transaction[%d], err_code[%p]", mail_ids, number_of_mails, transaction, err_code);
int rc, ret = false, i, cur_sql_query_string = 0;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
if (!mail_ids) {
- 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;
}
EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
}
/* Delete all mails mail_read_mail_uid_tbl table based on account id */
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION("no mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
}
if (!emstorage_notify_storage_event(NOTI_MAIL_DELETE_WITH_ACCOUNT, account_id, 0 , NULL, 0))
return ret;
}
-INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_mail_by_mailbox(int account_id, char *mailbox, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mbox[%p], transaction[%d], err_code[%p]", account_id, mbox, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code);
- if (account_id < FIRST_ACCOUNT_ID || !mbox) {
- EM_DEBUG_EXCEPTION(" account_id[%d], mbox[%p]", account_id, mbox);
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mailbox[%p]", account_id, mailbox);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mbox);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* Delete Mails from mail_read_mail_uid_tbl */
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mbox);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s'", account_id, mailbox);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
- if (!emstorage_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, 0 , mbox, 0))
+ if (!emstorage_notify_storage_event(NOTI_MAIL_DELETE_ALL, account_id, 0 , mailbox, 0))
EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAIL_DELETE_ALL ] >>>> ");
ret = true;
EM_DEBUG_EXCEPTION("mail_ilst[%p], count[%d]", mail_list, count);
if (err_code)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
EM_SAFE_FREE(p->subject);
EM_SAFE_FREE(p->file_path_plain);
EM_SAFE_FREE(p->file_path_html);
+ EM_SAFE_FREE(p->file_path_mime_entity);
EM_SAFE_FREE(p->message_id);
EM_SAFE_FREE(p->email_address_sender);
EM_SAFE_FREE(p->email_address_recipient);
}
if (err_code != NULL)
- *err_code = EMF_ERROR_NONE;
+ *err_code = EMAIL_ERROR_NONE;
EM_DEBUG_FUNC_END();
return true;
if (mail_id <= 0 || !count) {
EM_DEBUG_EXCEPTION("mail_id[%d], count[%p]", mail_id, count);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], input_transaction[%d], output_attachment_list[%p], output_attachment_count[%p]", input_mail_id, output_attachment_list, input_transaction, output_attachment_count);
if (input_mail_id <= 0 || !output_attachment_list || !output_attachment_count) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- return EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
}
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int i = 0;
int rc = -1;
char **result = NULL;
EMSTORAGE_START_READ_TRANSACTION(input_transaction);
SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", input_mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*output_attachment_count = atoi(result[1]);
sqlite3_free_table(result);
if(*output_attachment_count == 0) {
- error = EMF_ERROR_NONE;
+ error = EMAIL_ERROR_NONE;
goto FINISH_OFF;
}
if (!p_data_tbl) {
EM_DEBUG_EXCEPTION("em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
EM_DEBUG_LOG("sql_query_string [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no matched attachment found...");
- error = EMF_ERROR_ATTACHMENT_NOT_FOUND;
+ error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND;
goto FINISH_OFF;
}
for (i = 0; i < *output_attachment_count; i++) {
_get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl[i].mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl[i].account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _get_stmt_field_data_int (hStmt, &(p_data_tbl[i].mailbox_id), MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_save_status), ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_drm_type), ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int (hStmt, &(p_data_tbl[i].attachment_drm_method), ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL);
EM_DEBUG_LOG("attachment[%d].attachment_id : %d", i, p_data_tbl[i].attachment_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; }, ("sqlite3_step fail:%d", rc));
}
FINISH_OFF:
- if (error == EMF_ERROR_NONE)
+ if (error == EMAIL_ERROR_NONE)
*output_attachment_list = p_data_tbl;
else if (p_data_tbl != NULL)
emstorage_free_attachment(&p_data_tbl, *output_attachment_count, NULL);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed [%d]", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction);
return error;
}
-INTERNAL_FUNC int emstorage_get_attachment(int mail_id, int attachment_id, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_attachment(int attachment_id, emstorage_attachment_tbl_t** attachment, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, attachment_id, attachment, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p], transaction[%d], err_code[%p]", attachment_id, attachment, transaction, err_code);
- if (mail_id <= 0 || attachment_id <= 0 || !attachment) {
- EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d], attachment[%p]", mail_id, attachment_id, attachment);
+ if (attachment_id <= 0 || !attachment) {
+ EM_DEBUG_EXCEPTION("attachment_id[%d], attachment[%p]", attachment_id, attachment);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
emstorage_attachment_tbl_t* p_data_tbl = NULL;
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_READ_TRANSACTION(transaction);
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE mail_id = %d AND attachment_id = %d", mail_id, attachment_id);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_attachment_tbl WHERE attachment_id = %d", attachment_id);
sqlite3_stmt* hStmt = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION("no matched attachment found...");
- error = EMF_ERROR_ATTACHMENT_NOT_FOUND;
+ error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND;
goto FINISH_OFF;
}
if (!(p_data_tbl = (emstorage_attachment_tbl_t*)em_malloc(sizeof(emstorage_attachment_tbl_t) * 1))) {
EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
_get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_size), ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_save_status), ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_drm_type), ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL);
_get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_drm_method), ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL);
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION(" mail_id[%d], nth[%d], attachment[%p]", mail_id, nth, attachment_tbl);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
emstorage_attachment_tbl_t* p_data_tbl = NULL;
char *p = NULL;
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
DB_STMT hStmt = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION(" no matched attachment found...");
- error = EMF_ERROR_ATTACHMENT_NOT_FOUND;
+ error = EMAIL_ERROR_ATTACHMENT_NOT_FOUND;
goto FINISH_OFF;
}
if (!(p_data_tbl = (emstorage_attachment_tbl_t*)em_malloc(sizeof(emstorage_attachment_tbl_t) * 1))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
p_data_tbl->attachment_size = sqlite3_column_int(hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL);
p_data_tbl->mail_id = sqlite3_column_int(hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
p_data_tbl->account_id = sqlite3_column_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
- if ((p = (char *)sqlite3_column_text(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)strlen(p))
- p_data_tbl->mailbox_name = cpy_str(p);
+ p_data_tbl->mailbox_id = sqlite3_column_int(hStmt, MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL);
p_data_tbl->attachment_save_status = sqlite3_column_int(hStmt, ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL);
p_data_tbl->attachment_drm_type = sqlite3_column_int(hStmt, ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL);
p_data_tbl->attachment_drm_method = sqlite3_column_int(hStmt, ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL);
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, emf_mail_change_type_t type, emstorage_attachment_tbl_t* attachment, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_change_attachment_field(int mail_id, email_mail_change_type_t type, emstorage_attachment_tbl_t* attachment, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("mail_id[%d], type[%d], attachment[%p], transaction[%d], err_code[%p]", mail_id, type, attachment, transaction, err_code);
if (mail_id <= 0 || !attachment) {
EM_DEBUG_EXCEPTION(" mail_id[%d], type[%d], attachment[%p]", mail_id, type, attachment);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
switch (type) {
case UPDATE_MAILBOX:
EM_DEBUG_LOG("UPDATE_MAILBOX");
- if (!attachment->mailbox_name) {
- EM_DEBUG_EXCEPTION(" attachment->mailbox_name[%p]", attachment->mailbox_name);
- error = EMF_ERROR_INVALID_PARAM;
+ if (!attachment->mailbox_id) {
+ EM_DEBUG_EXCEPTION(" attachment->mailbox_id[%d]", attachment->mailbox_id);
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_attachment_tbl SET mailbox_name = ? WHERE mail_id = %d", mail_id);
-
-
+ "UPDATE mail_attachment_tbl SET mailbox_id = ? WHERE mail_id = %d", mail_id);
+
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
- _bind_stmt_field_data_string(hStmt, i++, (char *)attachment->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bind_stmt_field_data_int(hStmt, i++, attachment->mailbox_id);
break;
case UPDATE_SAVENAME:
EM_DEBUG_LOG("UPDATE_SAVENAME");
if (!attachment->attachment_path) {
EM_DEBUG_EXCEPTION(" attachment->attachment_path[%p]", attachment->attachment_path);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_int(hStmt, i++, attachment->attachment_size);
default:
EM_DEBUG_LOG("type[%d]", type);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EM_DEBUG_LOG("query = [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
}
-INTERNAL_FUNC int emstorage_rename_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_rename_mailbox(int input_mailbox_id, char *input_new_mailbox_name, char *input_new_mailbox_alias, int input_transaction)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_new_mailbox_name[%p], input_new_mailbox_alias [%p], input_transaction[%d]", input_mailbox_id, input_new_mailbox_name, input_new_mailbox_alias, input_transaction);
- if (account_id < FIRST_ACCOUNT_ID ||!old_mailbox_name || !new_mailbox_name) {
- EM_DEBUG_EXCEPTION("Invalid Parameters");
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;
- }
-
- int rc, ret = true;
- int error = EMF_ERROR_NONE;
+ int rc = 0;
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+ sqlite3 *local_db_handle = NULL;
+ int account_id = 0;
+ emstorage_mailbox_tbl_t *old_mailbox_data = NULL;
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_tbl SET"
- " mailbox_name = '%s'"
- " WHERE account_id = %d"
- " AND mailbox_name = '%s'"
- , new_mailbox_name
- , account_id
- , old_mailbox_name);
+ if (input_mailbox_id <= 0 || !input_new_mailbox_name || !input_new_mailbox_alias) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ local_db_handle = emstorage_get_db_connection();
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+ if ((error = emstorage_get_mailbox_by_id(input_mailbox_id, &old_mailbox_data)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", error);
+ goto FINISH_OFF;
+ }
+ account_id = old_mailbox_data->account_id;
- if (sqlite3_changes(local_db_handle) == 0)
- EM_DEBUG_LOG("no mail matched...");
+ EMSTORAGE_START_WRITE_TRANSACTION(input_transaction, error);
-
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_attachment_tbl SET"
+ "UPDATE mail_box_tbl SET"
" mailbox_name = '%s'"
- " WHERE account_id = %d"
- " AND mailbox_name = '%s'"
- , new_mailbox_name
- , account_id
- , old_mailbox_name);
+ ",alias = '%s'"
+ " WHERE mailbox_id = %d"
+ , input_new_mailbox_name
+ , input_new_mailbox_alias
+ , input_mailbox_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
- if (sqlite3_changes(local_db_handle) == 0)
- EM_DEBUG_LOG("no attachment matched...");
+ if (sqlite3_changes(local_db_handle) == 0)
+ EM_DEBUG_LOG("no mail_meeting_tbl matched...");
+ /* Update mail_tbl */
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_meeting_tbl SET"
+ "UPDATE mail_tbl SET"
" mailbox_name = '%s'"
- " WHERE account_id = %d"
- " AND mailbox_name = '%s'"
- , new_mailbox_name
- , account_id
- , old_mailbox_name);
+ " WHERE mailbox_id = %d"
+ , input_new_mailbox_name
+ , input_mailbox_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (sqlite3_changes(local_db_handle) == 0)
- EM_DEBUG_LOG("no mail_meeting_tbl matched...");
+ EM_DEBUG_LOG("no mail matched...");
ret = true;
FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
- _DISCONNECT_DB;
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-
-INTERNAL_FUNC int emstorage_change_attachment_mbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(input_transaction, ret, error);
- if (account_id < FIRST_ACCOUNT_ID || !old_mailbox_name || !new_mailbox_name) {
- EM_DEBUG_EXCEPTION(" account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p]", account_id, old_mailbox_name, new_mailbox_name);
-
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;
+ if (ret) {
+ if (!emstorage_notify_storage_event(NOTI_MAILBOX_RENAME, account_id, input_mailbox_id, input_new_mailbox_name, 0))
+ EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAILBOX_RENAME ] >>>> ");
}
-
- int rc, ret = true;
- int error = EMF_ERROR_NONE;
- char sql_query_string[QUERY_SIZE] = {0, };
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
-
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_attachment_tbl SET"
- " mailbox_name = '%s'"
- " WHERE account_id = %d"
- " AND mailbox_name = '%s'"
- , new_mailbox_name
- , account_id
- , old_mailbox_name);
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
- ("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- rc = sqlite3_changes(local_db_handle);
- if (rc == 0) {
- EM_DEBUG_EXCEPTION(" no attachment found...");
+ else {
+ if (!emstorage_notify_storage_event(NOTI_MAILBOX_RENAME_FAIL, account_id, input_mailbox_id, input_new_mailbox_name, 0))
+ EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event Failed [ NOTI_MAILBOX_RENAME_FAIL ] >>>> ");
}
- ret = true;
-
-FINISH_OFF:
+ if (old_mailbox_data)
+ emstorage_free_mailbox(&old_mailbox_data, 1, NULL);
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
_DISCONNECT_DB;
-
- if (err_code != NULL)
- *err_code = error;
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
+ EM_DEBUG_FUNC_END("error [%d]", error);
+ return error;
}
-
INTERNAL_FUNC int emstorage_get_new_attachment_no(int *attachment_no, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("attachment_no [%p], err_code[%p]", attachment_no, err_code);
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char *sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
char **result;
if (!attachment_no) {
EM_DEBUG_EXCEPTION("Invalid attachment");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL == result[1])
char *sql = NULL;
char **result;
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
if (!attachment_tbl) {
EM_DEBUG_EXCEPTION("attachment_tbl[%p], iscopy[%d]", attachment_tbl, iscopy);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
sql = "SELECT max(rowid) FROM mail_attachment_tbl;";
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL==result[1]) rc = 1;
", ?" /* attachment_size */
", ?" /* mail_id */
", ?" /* account_id */
- ", ?" /* mailbox_name */
+ ", ?" /* mailbox_id */
", ?" /* attachment_save_status */
", ?" /* attachment_drm_type */
", ?" /* attachment_drm_method */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_int (hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_id);
_bind_stmt_field_data_int (hStmt, ATTACHMENT_SIZE_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_size);
_bind_stmt_field_data_int (hStmt, MAIL_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->mail_id);
_bind_stmt_field_data_int (hStmt, ACCOUNT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->account_id);
- _bind_stmt_field_data_string(hStmt, MAILBOX_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bind_stmt_field_data_int (hStmt, MAILBOX_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->mailbox_id);
_bind_stmt_field_data_int (hStmt, ATTACHMENT_SAVE_STATUS_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_save_status);
_bind_stmt_field_data_int (hStmt, ATTACHMENT_DRM_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_drm_type);
_bind_stmt_field_data_int (hStmt, ATTACHMENT_DRM_METHOD_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_drm_method);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
/*
SNPRINTF(sql_query_string, sizeof(sql_query_string),
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*/
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_FUNC_BEGIN("attachment_tbl[%p], transaction[%d], err_code[%p]", attachment_tbl, transaction, err_code);
int rc, ret = false, field_idx = 0;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
if (!attachment_tbl) {
EM_DEBUG_EXCEPTION(" attachment_tbl[%p] ", attachment_tbl);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
", attachment_size = ?"
", mail_id = ?"
", account_id = ?"
- ", mailbox_name = ?"
+ ", mailbox_id = ?"
", attachment_save_status = ?"
", attachment_drm_type = ?"
", attachment_drm_method = ?"
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
_bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_size);
_bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->mail_id);
_bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->account_id);
- _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_ATTACHMENT_TBL);
+ _bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->mailbox_id);
_bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_save_status);
_bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_drm_type);
_bind_stmt_field_data_int (hStmt, field_idx++ , attachment_tbl->attachment_drm_method);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
/*
SNPRINTF(sql_query_string, sizeof(sql_query_string),
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*/
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no matched mail found...");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_delete_attachment_on_db(int mail_id, int attachment_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_attachment_on_db(int attachment_id, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment_id[%d], transaction[%d], err_code[%p]", mail_id, attachment_id, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("attachment_id[%d], transaction[%d], err_code[%p]", attachment_id, transaction, err_code);
- if (mail_id < 0 || attachment_id < 0) {
- EM_DEBUG_EXCEPTION("mail_id[%d], attachment_id[%d]", mail_id, attachment_id);
+ if (attachment_id < 0) {
+ EM_DEBUG_EXCEPTION("attachment_id[%d]", attachment_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl");
-
- if (mail_id) /* '0' means all mail */
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE mail_id = %d", mail_id);
- if (attachment_id) /* '0' means all attachment */
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " AND attachment_id = %d", attachment_id);
-
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE attachment_id = %d", attachment_id);
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ ret = true;
+
+FINISH_OFF:
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(int mail_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("mail_id[%d], transaction[%d], err_code[%p]", mail_id, transaction, err_code);
+
+ if (mail_id < 0) {
+ EM_DEBUG_EXCEPTION("mail_id[%d]", mail_id);
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc, ret = false;
+ int error = EMAIL_ERROR_NONE;
+ char sql_query_string[QUERY_SIZE] = {0, };
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE mail_id = %d", mail_id);
+
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
return ret;
}
-INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mbox, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(int account_id, char *mailbox, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mbox[%p], transaction[%d], err_code[%p]", account_id, mbox, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], transaction[%d], err_code[%p]", account_id, mailbox, transaction, err_code);
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc, ret = false;
char sql_query_string[QUERY_SIZE] = {0, };
if (account_id != ALL_ACCOUNT) /* '0' means all account */
SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " WHERE account_id = %d", account_id);
- if (mbox) /* NULL means all mailbox_name */
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mbox);
+ if (mailbox) /* NULL means all mailbox_name */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", mailbox);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
if ((attachment_tbl_list == NULL) || (*attachment_tbl_list == NULL)) {
EM_DEBUG_EXCEPTION(" attachment_tbl_list[%p], count[%d]", attachment_tbl_list, count);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int i;
for (i = 0; i < count; i++) {
- EM_SAFE_FREE(p[i].mailbox_name);
EM_SAFE_FREE(p[i].attachment_name);
EM_SAFE_FREE(p[i].attachment_path);
#ifdef __ATTACHMENT_OPTI__
}
if (err_code != NULL)
- *err_code = EMF_ERROR_NONE;
+ *err_code = EMAIL_ERROR_NONE;
EM_DEBUG_FUNC_END();
return true;
}
EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; },
("SQL(BEGIN) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle)));
if (ret == false && err_code != NULL)
- *err_code = EMF_ERROR_DB_FAILURE;
+ *err_code = EMAIL_ERROR_DB_FAILURE;
EM_PROFILE_END(emStorageBeginTransaction);
EM_DEBUG_FUNC_END("ret [%d]", ret);
LEAVE_CRITICAL_SECTION(_transactionEndLock);
if (ret == false && err_code != NULL)
- *err_code = EMF_ERROR_DB_FAILURE;
+ *err_code = EMAIL_ERROR_DB_FAILURE;
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
LEAVE_CRITICAL_SECTION(_transactionEndLock);
if (ret == false && err_code != NULL)
- *err_code = EMF_ERROR_DB_FAILURE;
+ *err_code = EMAIL_ERROR_DB_FAILURE;
EM_DEBUG_FUNC_END("ret [%d]", ret);
return ret;
}
-INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, emf_mailbox_t* mailbox_name, int *result, int *err_code)
+INTERNAL_FUNC int emstorage_is_mailbox_full(int account_id, email_mailbox_t *mailbox, int *result, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], result[%p], err_code[%p]", account_id, mailbox_name, result, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox[%p], result[%p], err_code[%p]", account_id, mailbox, result, err_code);
- if (account_id < FIRST_ACCOUNT_ID || !mailbox_name || !result) {
- if (mailbox_name)
- EM_DEBUG_EXCEPTION("Invalid Parameter. accoun_id[%d], mailbox_name[%p]", account_id, mailbox_name);
+ if (account_id < FIRST_ACCOUNT_ID || !mailbox || !result) {
+ if (mailbox)
+ EM_DEBUG_EXCEPTION("Invalid Parameter. accoun_id[%d], mailbox[%p]", account_id, mailbox);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int mail_count = 0;
- if (!emstorage_get_mail_count(account_id, mailbox_name->name, &mail_count, NULL, true, &error)) {
+ if (!emstorage_get_mail_count(account_id, mailbox->mailbox_name, &mail_count, NULL, true, &error)) {
EM_DEBUG_EXCEPTION("emstorage_get_mail_count failed [%d]", error);
goto FINISH_OFF;
}
- if (mailbox_name) {
- EM_DEBUG_LOG("mail_count[%d] mail_slot_size[%d]", mail_count, mailbox_name->mail_slot_size);
- if (mail_count >= mailbox_name->mail_slot_size)
+ if (mailbox) {
+ EM_DEBUG_LOG("mail_count[%d] mail_slot_size[%d]", mail_count, mailbox->mail_slot_size);
+ if (mail_count >= mailbox->mail_slot_size)
*result = true;
else
*result = false;
EM_DEBUG_FUNC_BEGIN("transaction[%d], err_code[%p]", transaction, err_code);
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
- const emf_db_object_t* tables = _g_db_tables;
- const emf_db_object_t* indexes = _g_db_indexes;
+ const email_db_object_t* tables = _g_db_tables;
+ const email_db_object_t* indexes = _g_db_indexes;
char data_path[256];
sqlite3 *local_db_handle = emstorage_get_db_connection();
if (indexes->data_flag) {
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP index %s", indexes->object_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
}
indexes++;
if (tables->data_flag) {
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP table %s", tables->object_name);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
}
EM_PROFILE_BEGIN(profile_emstorage_get_save_name);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char *dir_name = NULL;
char create_dir[1024]={0};
char *temp_file = NULL;
if (!name_buf || account_id < FIRST_ACCOUNT_ID || mail_id < 0 || atch_id < 0) {
EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if (!name_buf || account_id < FIRST_ACCOUNT_ID) {
EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], err_code[%p]", account_id, mail_id, atch_id, err_code);
EM_PROFILE_BEGIN(profile_emcore_save_create_dir);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char buf[512];
struct stat sbuf;
if (stat(buf, &sbuf) == 0) {
if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
EM_DEBUG_EXCEPTION("mkdir failed l(Errno=%d)][ErrStr=%s]", errno, strerror(errno));
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
if (mail_id > 0) {
if (account_id < FIRST_ACCOUNT_ID) {
EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
EM_DEBUG_EXCEPTION("mkdir failed l (Errno=%d)][ErrStr=%s]", errno, strerror(errno));
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
if (account_id < FIRST_ACCOUNT_ID || mail_id <= 0) {
EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d]", account_id, mail_id, atch_id);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
EM_DEBUG_EXCEPTION(" a object which isn't directory aleady exists");
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
else {
if (mkdir(buf, DIRECTORY_PERMISSION) != 0) {
EM_DEBUG_EXCEPTION(" mkdir failed [%s]", buf);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
EM_DEBUG_FUNC_BEGIN("src_file[%s], dst_file[%s], err_code[%p]", src_file, dst_file, err_code);
EM_DEBUG_LOG("Using the fsync function");
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
struct stat st_buf;
int fp_src = 0;
if (!src_file || !dst_file) {
EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if (stat(src_file, &st_buf) < 0) {
EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", src_file);
- error = EMF_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_INVALID_PATH; */
+ error = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_INVALID_PATH; */
goto FINISH_OFF;
}
if (!buf) {
EM_DEBUG_EXCEPTION(">>> Memory cannot be allocated");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
if (buf) {
if (!(fp_src = open(src_file, O_RDONLY))) {
EM_DEBUG_EXCEPTION(">>>> Source Fail open %s Failed [ %d ] - Error [ %s ]", src_file, errno, strerror(errno));
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (!(fp_dst = open(dst_file, O_CREAT | O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) {
EM_DEBUG_EXCEPTION(">>>> Destination Fail open %s Failed [ %d ] - Error [ %s ]", dst_file, errno, strerror(errno));
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
EM_DEBUG_LOG("Nread Value [%d]", nread);
if ((nwritten = write(fp_dst, buf, nread)) != nread) {
EM_DEBUG_EXCEPTION("fwrite failed...");
- error = EMF_ERROR_UNKNOWN;
+ error = EMAIL_ERROR_UNKNOWN;
goto FINISH_OFF;
}
EM_DEBUG_LOG("NWRITTEN [%d]", nwritten);
close(fp_dst);
}
EM_SAFE_FREE(buf);
- if (nread < 0 || error == EMF_ERROR_UNKNOWN)
+ if (nread < 0 || error == EMAIL_ERROR_UNKNOWN)
remove(dst_file);
if (err_code != NULL)
EM_DEBUG_FUNC_BEGIN("filename[%p], err_code[%p]", filename, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (filename == NULL) {
EM_DEBUG_EXCEPTION(" filename[%p]", filename);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
char *p = EM_SAFE_STRDUP(tempname);
if (p == NULL) {
EM_DEBUG_EXCEPTION(" strdup failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
char *match_str = NULL;
int nwritten = 0;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int data_count_to_written = 0;
char *temp_file_name = NULL;
int err = 0;
if (stat(file_path, &st_buf) < 0) {
EM_DEBUG_EXCEPTION(" stat(\"%s\") failed...", file_path);
- error = EMF_ERROR_SYSTEM_FAILURE; /* EMF_ERROR_INVALID_PATH; */
+ error = EMAIL_ERROR_SYSTEM_FAILURE; /* EMAIL_ERROR_INVALID_PATH; */
goto FINISH_OFF;
}
if (!(fp_src = fopen(file_path, "rb"))) {
EM_DEBUG_EXCEPTION(" file_path fopen failed - %s", file_path);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
/* Open the Temp file in Append mode */
if (!(fp_dest = fopen(temp_file_name, "ab"))) {
EM_DEBUG_EXCEPTION(" fopen failed - %s", temp_file_name);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (nwritten <= 0) {
EM_DEBUG_EXCEPTION(" Error Occured while writing Old data : [%d ] bytes written ", nwritten);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
else {
}
else {
EM_DEBUG_EXCEPTION(" Error Occured while writing New data : [%d ] bytes written ", nwritten);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN("src_file[%p], dst_file[%p], err_code[%p]", src_file, dst_file, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (src_file == NULL || dst_file == NULL) {
EM_DEBUG_EXCEPTION("src_file[%p], dst_file[%p]", src_file, dst_file);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EM_DEBUG_EXCEPTION("no dst file found [%s]", src_file);
EM_DEBUG_EXCEPTION("no file found [%d]", errno);
- error = EMF_ERROR_FILE_NOT_FOUND;
+ error = EMAIL_ERROR_FILE_NOT_FOUND;
goto FINISH_OFF;
}
else {
EM_DEBUG_EXCEPTION("rename failed [%d]", errno);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
}
EM_DEBUG_FUNC_BEGIN("src_file[%p], err_code[%p]", src_file, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
if (src_file == NULL) {
EM_DEBUG_EXCEPTION(" src_file[%p]", src_file);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if (errno != ENOENT) {
EM_DEBUG_EXCEPTION(" remove failed - %d", errno);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
else {
EM_DEBUG_EXCEPTION(" no file found...");
- error = EMF_ERROR_FILE_NOT_FOUND;
+ error = EMAIL_ERROR_FILE_NOT_FOUND;
}
}
EM_DEBUG_EXCEPTION(" src_dir[%p]", src_dir);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DIR *dirp;
struct dirent *dp;
if (errno == ENOENT) {
EM_DEBUG_EXCEPTION("directory[%s] does not exist...", src_dir);
if (err_code != NULL)
- *err_code = EMF_ERROR_SYSTEM_FAILURE;
+ *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
return true;
}
else {
EM_DEBUG_EXCEPTION("opendir failed - %d", errno);
if (err_code != NULL)
- *err_code = EMF_ERROR_SYSTEM_FAILURE;
+ *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
return false;
}
}
EM_DEBUG_EXCEPTION("remove failed - %s", buf);
closedir(dirp);
if (err_code != NULL)
- *err_code = EMF_ERROR_SYSTEM_FAILURE;
+ *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
return false;
}
}
if (remove(src_dir) < 0) {
EM_DEBUG_EXCEPTION("remove failed [%s]", src_dir);
if (err_code != NULL)
- *err_code = EMF_ERROR_SYSTEM_FAILURE;
+ *err_code = EMAIL_ERROR_SYSTEM_FAILURE;
return false;
}
{
EM_DEBUG_FUNC_BEGIN("new_server_uid[%s], old_server_uid[%s]", new_server_uid, old_server_uid);
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
int transaction = true;
if (!old_server_uid || !new_server_uid) {
EM_DEBUG_EXCEPTION("Invalid parameters");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
return false;
}
sqlite3 *local_db_handle = emstorage_get_db_connection();
"UPDATE mail_tbl SET server_mail_id=\'%s\' WHERE server_mail_id=%s ", new_server_uid, old_server_uid);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
EM_DEBUG_FUNC_BEGIN("mail_id[%d], new_server_uid[%s], mbox_name[%s]", mail_id, new_server_uid, mbox_name);
int rc, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
int transaction = true;
if (!mail_id || !new_server_uid || !mbox_name) {
EM_DEBUG_EXCEPTION("Invalid parameters");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
return false;
}
sqlite3 *local_db_handle = emstorage_get_db_connection();
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\', local_mbox=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id);
+ "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\', mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
if ((!mail_id) ||(account_id <= 0 && account_id != -1)) {
EM_DEBUG_EXCEPTION(" mail_id[%p], account_id[%d] ", mail_id, account_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
int rc = -1;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
int count = 0;
int mailid = 0;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
char **result;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
sqlite3_free_table(result);
if (count == 0) {
EM_DEBUG_EXCEPTION("no Mails found...");
ret = false;
- error= EMF_ERROR_MAIL_NOT_FOUND;
+ error= EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
EM_DEBUG_EXCEPTION("total_usage[%p]", total_usage);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char syscmd[256] = {0, };
char line[256] = {0, };
char *line_from_file = NULL;
if (setting_system_command(syscmd) == -1) {
EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (setting_system_command(syscmd) == -1) {
EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : Setting > Memory] System Command [%s] is failed", syscmd);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (fp == NULL) {
perror(SETTING_MEMORY_TEMP_FILE_PATH);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if(line_from_file == NULL) {
EM_DEBUG_EXCEPTION("fgets failed");
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
total_diskusage = strtoul(line, NULL, 10);
SNPRINTF(syscmd, sizeof(syscmd), "rm -f %s", SETTING_MEMORY_TEMP_FILE_PATH);
if (setting_system_command(syscmd) == -1) {
EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd);
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
{
DB_STMT hStmt = NULL;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc = 0;
char sql_query_string[QUERY_SIZE] = {0, };
", ?" /* alias_sender */
", ?" /* alias_recipient */
", ?" /* thread_item_count */
- ", ?" /* meeting_request_status */
+ ", ?" /* meeting_request_status */
+ ", ?" /* message_class */
+ ", ?" /* digest_type */
+ ", ?" /* smime_type */
")");
int transaction = true;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
_bind_stmt_field_data_int(hStmt, MAIL_ID_IDX_IN_MAIL_TBL, mail_id);
_bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_TBL, account_id);
_bind_stmt_field_data_string(hStmt, MAILBOX_NAME_IDX_IN_MAIL_TBL, "OUTBOX", 0, MAILBOX_LEN_IN_MAIL_TBL);
- _bind_stmt_field_data_int(hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, EMF_MAILBOX_TYPE_OUTBOX);
+ _bind_stmt_field_data_int(hStmt, MAILBOX_TYPE_IDX_IN_MAIL_TBL, EMAIL_MAILBOX_TYPE_OUTBOX);
_bind_stmt_field_data_string(hStmt, SUBJECT_IDX_IN_MAIL_TBL, "save test - long", 1, SUBJECT_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_string(hStmt, DATETIME_IDX_IN_MAIL_TBL, "20100316052908", 0, DATETIME_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int(hStmt, SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL, 0);
_bind_stmt_field_data_int(hStmt, THREAD_ITEM_COUNT_IDX_IN_MAIL_TBL, 0);
_bind_stmt_field_data_string(hStmt, PREVIEW_TEXT_IDX_IN_MAIL_TBL, "preview body", 1, PREVIEWBODY_LEN_IN_MAIL_TBL);
_bind_stmt_field_data_int(hStmt, MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL, 0);
+ _bind_stmt_field_data_int(hStmt, MESSAGE_CLASS_IDX_IN_MAIL_TBL, 0);
+ _bind_stmt_field_data_int(hStmt, DIGEST_TYPE_IDX_IN_MAIL_TBL, 0);
+ _bind_stmt_field_data_int(hStmt, SMIME_TYPE_IDX_IN_MAIL_TBL, 0);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_PROFILE_BEGIN(profile_emstorage_get_thread_id_of_thread_mails);
int rc = 0, query_size = 0, query_size_account = 0;
int account_id = 0;
- int err_code = EMF_ERROR_NONE;
+ int err_code = EMAIL_ERROR_NONE;
int count = 0, result_thread_id = -1, latest_mail_id_in_thread = -1;
time_t latest_date_time = 0;
time_t date_time = 0;
char stripped_subject[1025];
sqlite3 *local_db_handle = emstorage_get_db_connection();
- EM_IF_NULL_RETURN_VALUE(mail_tbl, EMF_ERROR_INVALID_PARAM);
- EM_IF_NULL_RETURN_VALUE(thread_id, EMF_ERROR_INVALID_PARAM);
- EM_IF_NULL_RETURN_VALUE(result_latest_mail_id_in_thread, EMF_ERROR_INVALID_PARAM);
- EM_IF_NULL_RETURN_VALUE(thread_item_count, EMF_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(mail_tbl, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(thread_id, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(result_latest_mail_id_in_thread, EMAIL_ERROR_INVALID_PARAM);
+ EM_IF_NULL_RETURN_VALUE(thread_item_count, EMAIL_ERROR_INVALID_PARAM);
- if (mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_TRASH ||
- mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_SPAMBOX ||
- mail_tbl->mailbox_type == EMF_MAILBOX_TYPE_ALL_EMAILS) {
+ if (mail_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_TRASH ||
+ mail_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_SPAMBOX ||
+ mail_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_ALL_EMAILS) {
EM_DEBUG_LOG("the mail in trash, spambox, all email could not be thread mail.");
goto FINISH_OFF;
}
EM_DEBUG_LOG("subject : %s", subject);
- if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject) != EMF_ERROR_NONE) {
+ if (em_find_pos_stripped_subject_for_thread_view(subject, stripped_subject) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed");
- err_code = EMF_ERROR_UNKNOWN;
+ err_code = EMAIL_ERROR_UNKNOWN;
result_thread_id = -1;
goto FINISH_OFF;
}
sql_account = malloc(query_size_account);
if (sql_account == NULL) {
EM_DEBUG_EXCEPTION("malloc for sql_account is failed %d", query_size_account);
- err_code = EMF_ERROR_OUT_OF_MEMORY;
+ err_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
snprintf(sql_account, query_size_account, sql_format_account, account_id);
if (sql_query_string == NULL) {
EM_DEBUG_EXCEPTION("malloc for sql is failed %d", query_size);
- err_code = EMF_ERROR_OUT_OF_MEMORY;
+ err_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG("Result rows count : %d", count);
EM_DEBUG_FUNC_BEGIN();
int count = 0, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
emstorage_mail_tbl_t *p_data_tbl = NULL;
char conditional_clause[QUERY_SIZE] = {0, };
}
-INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], search_type [%d], search_value [%p], sorting [%d], sender_list[%p], sender_count[%p] err_code[%p]"
, account_id , mailbox_name , search_type , search_value , sorting , sender_list, sender_count, err_code);
if ((!sender_list) ||(!sender_count)) {
- EM_DEBUG_EXCEPTION("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;
}
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int count = 0;
int i, col_index = 0;
int read_count = 0;
- emf_sender_list_t *p_sender_list = NULL;
+ email_sender_list_t *p_sender_list = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
char **result = NULL;
sqlite3 *local_db_handle = emstorage_get_db_connection();
if (search_value) {
switch (search_type) {
- case EMF_SEARCH_FILTER_SUBJECT:
+ case EMAIL_SEARCH_FILTER_SUBJECT:
SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
" AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", search_value);
break;
- case EMF_SEARCH_FILTER_SENDER:
+ case EMAIL_SEARCH_FILTER_SENDER:
SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
" AND ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
") ", search_value);
break;
- case EMF_SEARCH_FILTER_RECIPIENT:
+ case EMAIL_SEARCH_FILTER_RECIPIENT:
SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
" AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) "
" OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) "
" OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) "
") ", search_value, search_value, search_value);
break;
- case EMF_SEARCH_FILTER_ALL:
+ case EMAIL_SEARCH_FILTER_ALL:
SNPRINTF(sql_query_string + strlen(sql_query_string), QUERY_SIZE-(strlen(sql_query_string)+1),
" AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') "
" OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) "
EM_DEBUG_LOG("query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG("Count of Sender [%d]", count);
- if (!(p_sender_list = (emf_sender_list_t*)em_malloc(sizeof(emf_sender_list_t) * count))) {
+ if (!(p_sender_list = (email_sender_list_t*)em_malloc(sizeof(email_sender_list_t) * count))) {
EM_DEBUG_EXCEPTION("em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
return ret;
}
-INTERNAL_FUNC int emstorage_free_sender_list(emf_sender_list_t **sender_list, int count)
+INTERNAL_FUNC int emstorage_free_sender_list(email_sender_list_t **sender_list, int count)
{
EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count);
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
if (count > 0) {
if (!sender_list || !*sender_list) {
EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
return err;
}
- emf_sender_list_t* p = *sender_list;
+ email_sender_list_t* p = *sender_list;
int i = 0;
for (; i < count; i++) {
}
-INTERNAL_FUNC int emstorage_free_address_info_list(emf_address_info_list_t **address_info_list)
+INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **address_info_list)
{
EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
- int err = EMF_ERROR_NONE;
- emf_address_info_t *p_address_info = NULL;
+ int err = EMAIL_ERROR_NONE;
+ email_address_info_t *p_address_info = NULL;
GList *list = NULL;
GList *node = NULL;
int i = 0;
if (!address_info_list || !*address_info_list) {
EM_DEBUG_EXCEPTION("address_info_list[%p]", address_info_list);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
return err;
}
/* delete GLists */
- for (i = EMF_ADDRESS_TYPE_FROM; i <= EMF_ADDRESS_TYPE_BCC; i++) {
+ for (i = EMAIL_ADDRESS_TYPE_FROM; i <= EMAIL_ADDRESS_TYPE_BCC; i++) {
switch (i) {
- case EMF_ADDRESS_TYPE_FROM:
+ case EMAIL_ADDRESS_TYPE_FROM:
list = (*address_info_list)->from;
break;
- case EMF_ADDRESS_TYPE_TO:
+ case EMAIL_ADDRESS_TYPE_TO:
list = (*address_info_list)->to;
break;
- case EMF_ADDRESS_TYPE_CC:
+ case EMAIL_ADDRESS_TYPE_CC:
list = (*address_info_list)->cc;
break;
- case EMF_ADDRESS_TYPE_BCC:
+ case EMAIL_ADDRESS_TYPE_BCC:
list = (*address_info_list)->bcc;
break;
}
/* delete dynamic-allocated memory for each item */
node = g_list_first(list);
while (node != NULL) {
- p_address_info = (emf_address_info_t*)node->data;
+ p_address_info = (email_address_info_t*)node->data;
EM_SAFE_FREE(p_address_info->address);
EM_SAFE_FREE(p_address_info->display_name);
EM_SAFE_FREE(node->data);
}
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
-INTERNAL_FUNC int emstorage_add_pbd_activity(emf_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_pbd_activity(email_event_partial_body_thd* local_activity, int *activity_id, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("local_activity[%p], activity_id[%p], transaction[%d], err_code[%p]", local_activity, activity_id, transaction, err_code);
if (!local_activity || !activity_id) {
EM_DEBUG_EXCEPTION("local_activity[%p], transaction[%d], activity_id[%p], err_code[%p]", local_activity, activity_id, transaction, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int i = 0;
char sql_query_string[QUERY_SIZE] = {0, };
",?" /* Server mail ID */
",?" /* Activity ID */
",?" /* Activity type*/
+ ",?" /* Mailbox ID*/
",?" /* Mailbox name*/
") ");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL==result[1]) rc = 1;
EM_DEBUG_LOG(">>>>> ACTIVITY ID [ %d ], MAIL ID [ %d ], ACTIVITY TYPE [ %d ], SERVER MAIL ID [ %lu ]", \
local_activity->activity_id, local_activity->mail_id, local_activity->activity_type, local_activity->server_mail_id);
- if (local_activity->mailbox_name)
- EM_DEBUG_LOG(" MAILBOX NAME [ %s ]", local_activity->mailbox_name);
+ if (local_activity->mailbox_id)
+ EM_DEBUG_LOG(" MAILBOX ID [ %d ]", local_activity->mailbox_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG(">>>> SQL STMT [ %s ]", sql_query_string);
_bind_stmt_field_data_int(hStmt, i++, local_activity->server_mail_id);
_bind_stmt_field_data_int(hStmt, i++, local_activity->activity_id);
_bind_stmt_field_data_int(hStmt, i++, local_activity->activity_type);
+ _bind_stmt_field_data_int(hStmt, i++, local_activity->mailbox_id);
_bind_stmt_field_data_string(hStmt, i++ , (char *)local_activity->mailbox_name, 0, 3999);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
ret = true;
hStmt = NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
}
-INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, char *** mailbox_list, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(int account_id, int **mailbox_list, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
if (account_id < FIRST_ACCOUNT_ID || NULL == &mailbox_list || NULL == count) {
EM_DEBUG_EXCEPTION("account_id[%d], mailbox_list[%p], count[%p] err_code[%p]", account_id, mailbox_list, count, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char **result;
int i = 0, rc = -1;
- char **mbox_list = NULL;
+ int *mbox_list = NULL;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(distinct mailbox_name) FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_name", account_id);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(distinct mailbox_id) FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_id", account_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
if (!*count) {
EM_DEBUG_EXCEPTION(" no mailbox_name found...");
- error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
ret = true;
goto FINISH_OFF;
}
memset(sql_query_string, 0x00, sizeof(sql_query_string));
/* SNPRINTF(g_sql_query, sizeof(g_sql_query), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by activity_id", account_id); */
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_name FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_name", account_id);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT distinct mailbox_id FROM mail_partial_body_activity_tbl WHERE account_id = %d order by mailbox_id", account_id);
EM_DEBUG_LOG(" Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- if (NULL == (mbox_list = (char **)em_malloc(sizeof(char *) * (*count)))) {
+ if (NULL == (mbox_list = (int *)em_malloc(sizeof(int *) * (*count)))) {
EM_DEBUG_EXCEPTION(" em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
- memset(mbox_list, 0x00, sizeof(char *) * (*count));
+ memset(mbox_list, 0x00, sizeof(int) * (*count));
for (i = 0; i < (*count); i++) {
- _get_stmt_field_data_string(hStmt, &mbox_list[i], 0, ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
-
+ _get_stmt_field_data_int(hStmt, mbox_list + i, 0);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
/* EM_DEBUG_LOG("In emstorage_get_pdb_mailbox_list() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_LOG("mbox_list %s", mbox_list[i]);
+ EM_DEBUG_LOG("mbox_list %d", mbox_list + i);
}
ret = true;
hStmt = NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
if (NULL == &account_list || NULL == count) {
EM_DEBUG_EXCEPTION("mailbox_list[%p], count[%p] err_code[%p]", account_list, count, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char *sql;
char **result;
int i = 0, rc = -1;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
if (!*count) {
EM_DEBUG_EXCEPTION("no account found...");
- error = EMF_ERROR_MAILBOX_NOT_FOUND;
+ error = EMAIL_ERROR_MAILBOX_NOT_FOUND;
ret = true;
goto FINISH_OFF;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (NULL == (result_account_list = (int *)em_malloc(sizeof(int) * (*count)))) {
EM_DEBUG_EXCEPTION(" em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
_get_stmt_field_data_int(hStmt, result_account_list + i, 0);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
EM_DEBUG_LOG("account id -> %d", result_account_list[i]);
}
hStmt = NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
-INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, char *mailbox_name, emf_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_pbd_activity_data(int account_id, int input_mailbox_id, email_event_partial_body_thd** event_start, int *count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], event_start[%p], err_code[%p]", account_id, event_start, err_code);
- if (account_id < FIRST_ACCOUNT_ID || NULL == event_start || NULL == mailbox_name || NULL == count) {
- EM_DEBUG_EXCEPTION("account_id[%d], emf_event_partial_body_thd[%p], mailbox_name[%p], count[%p], err_code[%p]", account_id, event_start, mailbox_name, count, err_code);
+ if (account_id < FIRST_ACCOUNT_ID || NULL == event_start || 0 == input_mailbox_id || NULL == count) {
+ EM_DEBUG_EXCEPTION("account_id[%d], email_event_partial_body_thd[%p], input_mailbox_id[%d], count[%p], err_code[%p]", account_id, event_start, input_mailbox_id, count, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
char **result;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int i = 0;
DB_STMT hStmt = NULL;
- emf_event_partial_body_thd* event_list = NULL;
+ email_event_partial_body_thd* event_list = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_name = '%s' order by activity_id", account_id, mailbox_name);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
*count = atoi(result[1]);
if (!*count) {
EM_DEBUG_EXCEPTION("No matched activity found in mail_partial_body_activity_tbl");
- error = EMF_ERROR_MAIL_NOT_FOUND;
+ error = EMAIL_ERROR_MAIL_NOT_FOUND;
ret = true;
goto FINISH_OFF;
}
EM_DEBUG_LOG("Activity Count = %d", *count);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_name = '%s' order by activity_id", account_id, mailbox_name);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_partial_body_activity_tbl WHERE account_id = %d AND mailbox_id = '%d' order by activity_id", account_id, input_mailbox_id);
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- if (!(event_list = (emf_event_partial_body_thd*)em_malloc(sizeof(emf_event_partial_body_thd) * (*count)))) {
+ if (!(event_list = (email_event_partial_body_thd*)em_malloc(sizeof(email_event_partial_body_thd) * (*count)))) {
EM_DEBUG_EXCEPTION("Malloc failed");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
- memset(event_list, 0x00, sizeof(emf_event_partial_body_thd) * (*count));
+ memset(event_list, 0x00, sizeof(email_event_partial_body_thd) * (*count));
for (i=0; i < (*count); i++) {
_get_stmt_field_data_int(hStmt, &(event_list[i].account_id), ACCOUNT_IDX_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
_get_stmt_field_data_int(hStmt, (int *)&(event_list[i].server_mail_id), SERVER_MAIL_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
_get_stmt_field_data_int(hStmt, &(event_list[i].activity_id), ACTIVITY_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
_get_stmt_field_data_int(hStmt, &(event_list[i].activity_type), ACTIVITY_TYPE_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
+ _get_stmt_field_data_int(hStmt, &(event_list[i].mailbox_id), MAILBOX_ID_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
_get_stmt_field_data_string(hStmt, &(event_list[i].mailbox_name), 0, MAILBOX_NAME_IDX_IN_MAIL_PARTIAL_BODY_ACTIVITY_TBL);
-
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
/* EM_DEBUG_LOG("In emstorage_get_pbd_activity_data() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
event_list[i].event_type = 0;
if (true == ret)
*event_start = event_list;
else {
- if (event_list) {
- for (i=0; i < (*count); i++)
- EM_SAFE_FREE(event_list[i].mailbox_name);
- EM_SAFE_FREE(event_list);
- }
+ EM_SAFE_FREE(event_list);
}
if (hStmt != NULL) {
hStmt = NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d], activity_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, activity_id, transaction, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* validate activity existence */
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION("No matching activity found");
- error = EMF_ERROR_DATA_NOT_FOUND;
+ error = EMAIL_ERROR_DATA_NOT_FOUND;
ret = true;
goto FINISH_OFF;
}
return ret;
}
-INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, char *mailbox_name, int *activity_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(int account_id, int input_mailbox_id, int *activity_count, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
if (account_id < FIRST_ACCOUNT_ID || NULL == activity_count || NULL == err_code) {
EM_DEBUG_EXCEPTION("account_id[%d], activity_count[%p], err_code[%p]", account_id, activity_count, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
DB_STMT hStmt = NULL;
EMSTORAGE_START_READ_TRANSACTION(transaction);
memset(sql_query_string, 0x00, sizeof(sql_query_string));
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d and mailbox_name = '%s'", account_id, mailbox_name);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT count(*) FROM mail_partial_body_activity_tbl WHERE account_id = %d and mailbox_id = '%d'", account_id, input_mailbox_id);
EM_DEBUG_LOG(" Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
_get_stmt_field_data_int(hStmt, activity_count, 0);
hStmt=NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
}
if (NULL == activity_count || NULL == err_code) {
EM_DEBUG_EXCEPTION("activity_count[%p], err_code[%p]", activity_count, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
_get_stmt_field_data_int(hStmt, activity_count, 0);
hStmt=NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
EM_DEBUG_LOG("sqlite3_finalize- %d", rc);
}
if (account_id < FIRST_ACCOUNT_ID) {
EM_DEBUG_EXCEPTION("account_id[%d], transaction[%d], err_code[%p]", account_id, transaction, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION("No matching activities found in mail_partial_body_activity_tbl");
- error = EMF_ERROR_DATA_NOT_FOUND;
+ error = EMAIL_ERROR_DATA_NOT_FOUND;
ret = true;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN("old_server_uid[%s], new_server_uid[%s], mbox_name[%s]", old_server_uid, new_server_uid, mbox_name);
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
int transaction = true;
if (!old_server_uid || !new_server_uid || !mbox_name) {
EM_DEBUG_EXCEPTION("Invalid parameters");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
return false;
}
EM_DEBUG_LOG("Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl");
- error = EMF_ERROR_DATA_NOT_FOUND;
+ error = EMAIL_ERROR_DATA_NOT_FOUND;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN("file_size[%d] , dst_file_name[%s], err_code[%p]", file_size, dst_file_name, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
FILE* fp_dst = NULL;
if (!data_string || !dst_file_name) {
EM_DEBUG_EXCEPTION("data_string[%p], dst_file_name[%p]", data_string, dst_file_name);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if (!fp_dst) {
EM_DEBUG_EXCEPTION("fopen failed - %s", dst_file_name);
if (errno == 28)
- error = EMF_ERROR_MAIL_MEMORY_FULL;
+ error = EMAIL_ERROR_MAIL_MEMORY_FULL;
else
- error = EMF_ERROR_SYSTEM_FAILURE;
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
if (fwrite(data_string, 1, file_size, fp_dst) < 0) {
EM_DEBUG_EXCEPTION("fwrite failed...");
- error = EMF_ERROR_UNKNOWN;
+ error = EMAIL_ERROR_UNKNOWN;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN();
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
int transaction = true;
if (!old_server_uid || !new_server_uid || !mbox_name) {
EM_DEBUG_EXCEPTION("Invalid parameters");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
return false;
}
SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\' , local_mbox=\'%s\', mailbox_name=\'%s\' WHERE s_uid=%s ", new_server_uid, mbox_name, mbox_name, old_server_uid);
+ "UPDATE mail_read_mail_uid_tbl SET s_uid=\'%s\' , mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE s_uid=%s ", new_server_uid, mbox_name, mbox_name, old_server_uid);
EM_DEBUG_LOG(" Query [%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (rc == 0)
{
EM_DEBUG_EXCEPTION("No matching found in mail_partial_body_activity_tbl");
- error = EMF_ERROR_DATA_NOT_FOUND;
+ error = EMAIL_ERROR_DATA_NOT_FOUND;
goto FINISH_OFF;
}
/**
- * @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, emf_id_set_t** server_uids, int *id_set_count, int *err_code);
+ * @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, email_id_set_t** server_uids, int *id_set_count, int *err_code);
* Prepare an array of mail_id and corresponding server mail id.
*
*@author h.gahlaut@samsung.com
* @return This function returns true on success or false on failure.
*/
-INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, emf_id_set_t** idset, int *id_set_count, int *err_code)
+INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *mail_ids, email_id_set_t** idset, int *id_set_count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds);
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int ret = false;
- emf_id_set_t* p_id_set = NULL;
+ email_id_set_t* p_id_set = NULL;
int count = 0;
const int buf_size = QUERY_SIZE;
char sql_query_string[QUERY_SIZE] = {0, };
if (NULL == mail_ids || NULL == idset || NULL == id_set_count) {
EM_DEBUG_EXCEPTION("Invalid Parameters mail_ids[%p] idset[%p] id_set_count [%p]", mail_ids, idset, id_set_count);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
/* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG(" Count of mails [%d ]", count);
if (count <= 0) {
EM_DEBUG_EXCEPTION("Can't find proper mail");
- error = EMF_ERROR_DATA_NOT_FOUND;
+ error = EMAIL_ERROR_DATA_NOT_FOUND;
goto FINISH_OFF;
}
- if (NULL == (p_id_set = (emf_id_set_t*)em_malloc(sizeof(emf_id_set_t) * count))) {
+ if (NULL == (p_id_set = (email_id_set_t*)em_malloc(sizeof(email_id_set_t) * count))) {
EM_DEBUG_EXCEPTION(" em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
{
EM_DEBUG_FUNC_BEGIN();
int rc, ret = true, transaction = true;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
sqlite3 *local_db_handle = emstorage_get_db_connection();
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerDelete;");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerInsert;");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerUpdate;");
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
return ret;
}
-INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, char *dest_mailbox_name, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
+INTERNAL_FUNC int emstorage_filter_mails_by_rule(int account_id, int dest_mailbox_id, emstorage_rule_tbl_t *rule, int ** filtered_mail_id_list, int *count_of_mails, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_name[%p] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_name, rule, filtered_mail_id_list, count_of_mails, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], dest_mailbox_id[%d] rule[%p], filtered_mail_id_list[%p], count_of_mails[%p], err_code[%p]", account_id, dest_mailbox_id, rule, filtered_mail_id_list, count_of_mails, err_code);
- if ((account_id <= 0) || (!dest_mailbox_name) || (!rule) || (!rule->value)|| (!filtered_mail_id_list) || (!count_of_mails)) {
+ if ((account_id <= 0) || (dest_mailbox_id <= 0) || (!rule) || (!rule->value)|| (!filtered_mail_id_list) || (!count_of_mails)) {
EM_DEBUG_EXCEPTION("Invalid Parameter");
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
- int rc = -1, ret = false, error = EMF_ERROR_NONE;
+ int rc = -1, ret = false, error = EMAIL_ERROR_NONE;
int count = 0, col_index = 0, i = 0, where_pararaph_length = 0, *mail_list = NULL;
char **result = NULL, *where_pararaph = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
if (where_pararaph == NULL) {
EM_DEBUG_EXCEPTION("malloc failed for where_pararaph.");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
EM_DEBUG_LOG("rule->type [%d], rule->flag2[%d]", rule->type, rule->flag2);
- if (rule->type == EMF_FILTER_FROM) {
+ if (rule->type == EMAIL_FILTER_FROM) {
if (rule->flag2 == RULE_TYPE_INCLUDES)
SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND full_address_from like \'%%%s%%\'", account_id, rule->value);
else /* RULE_TYPE_EXACTLY */
SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND full_address_from = \'%s\'", account_id, rule->value);
}
- else if (rule->type == EMF_FILTER_SUBJECT) {
+ else if (rule->type == EMAIL_FILTER_SUBJECT) {
if (rule->flag2 == RULE_TYPE_INCLUDES)
SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND subject like \'%%%s%%\'", account_id, rule->value);
else /* RULE_TYPE_EXACTLY */
SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_type NOT in (3,5) AND subject = \'%s\'", account_id, rule->value);
}
else {
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
EM_DEBUG_EXCEPTION("rule->type is invald");
goto FINISH_OFF;
}
/* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG("Count of mails [%d]", count);
mail_list = malloc(sizeof(int) * count);
if (mail_list == NULL) {
EM_DEBUG_EXCEPTION("malloc failed for mail_list.");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
for (i = 0; i < count; i++)
_get_table_field_data_int(result, &(mail_list[i]), col_index++);
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_name = \'%s\', mailbox_type = 5 ", dest_mailbox_name);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET mailbox_id = %d, mailbox_type = 5 ", dest_mailbox_id);
if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE)
strcat(sql_query_string, where_pararaph);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
}
return ret;
}
-#define EMF_SLOT_UNIT 25
+#define EMAIL_SLOT_UNIT 25
-INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, char *mailbox_name, int new_slot_size, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_name, new_slot_size, err_code);
- int rc = -1, ret = false, err = EMF_ERROR_NONE;
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%p] new_slot_size[%d], err_code[%p]", account_id, mailbox_id, new_slot_size, err_code);
+ int rc = -1, ret = false, err = EMAIL_ERROR_NONE;
int where_pararaph_length = 0;
char *where_pararaph = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
if (new_slot_size > 0)
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = %d ", new_slot_size);
else if (new_slot_size == 0)
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", EMF_SLOT_UNIT);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", EMAIL_SLOT_UNIT);
else
SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_box_tbl SET mail_slot_size = mail_slot_size + %d ", new_slot_size * -1);
- if (mailbox_name)
- where_pararaph_length = strlen(mailbox_name) + 80;
+ if (mailbox_id)
+ where_pararaph_length = 80;
else
where_pararaph_length = 50;
where_pararaph = malloc(sizeof(char) * where_pararaph_length);
if (where_pararaph == NULL) {
EM_DEBUG_EXCEPTION("Memory allocation failed for where_pararaph");
- err = EMF_ERROR_OUT_OF_MEMORY;
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
memset(where_pararaph, 0x00, where_pararaph_length);
if (account_id > ALL_ACCOUNT) {
and = 1;
- if (mailbox_name)
- SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d AND mailbox_name = '%s' ", account_id, mailbox_name);
+ if (mailbox_id)
+ SNPRINTF(where_pararaph, where_pararaph_length, "WHERE mailbox_id = %d ", mailbox_id);
else
SNPRINTF(where_pararaph, where_pararaph_length, "WHERE account_id = %d ", account_id);
}
strcat(sql_query_string, where_pararaph);
else {
EM_DEBUG_EXCEPTION("Query buffer overflowed !!!");
- err = EMF_ERROR_OUT_OF_MEMORY;
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
EM_DEBUG_LOG("query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
return ret;
}
-INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, char *mailbox_name, emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_add_meeting_request(int account_id, int input_mailbox_id, email_meeting_request_t* meeting_req, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], meeting_req[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, meeting_req, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, input_mailbox_id, meeting_req, transaction, err_code);
if (!meeting_req || meeting_req->mail_id <= 0) {
if (meeting_req)
EM_DEBUG_EXCEPTION("mail_id[%]d", meeting_req->mail_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
int col_index = 0;
"INSERT INTO mail_meeting_tbl VALUES "
"( ?" /* mail_id */
", ?" /* account_id */
- ", ?" /* mailbox_name */
+ ", ?" /* mailbox_id */
", ?" /* meeting_response */
", ?" /* start_time */
", ?" /* end_time */
EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt);
EM_DEBUG_EXCEPTION("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle));
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
goto FINISH_OFF;
}
*/
_bind_stmt_field_data_int(hStmt, col_index++, meeting_req->mail_id);
_bind_stmt_field_data_int(hStmt, col_index++, account_id);
- _bind_stmt_field_data_string(hStmt, col_index++, (char *)mailbox_name, 0, MAILBOX_LEN_IN_MAIL_MEETING_TBL);
+ _bind_stmt_field_data_int(hStmt, col_index++, input_mailbox_id);
_bind_stmt_field_data_int(hStmt, col_index++, meeting_req->meeting_response);
temp_unix_time = timegm(&(meeting_req->start_time));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
rc = sqlite3_finalize(hStmt);
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, emf_meeting_request_t ** meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_meeting_request(int mail_id, email_meeting_request_t ** meeting_req, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN();
int count = 0;
int rc = -1;
int ret = false;
- int error = EMF_ERROR_NONE;
- emf_meeting_request_t *p_temp_meeting_req = NULL;
+ int error = EMAIL_ERROR_NONE;
+ email_meeting_request_t *p_temp_meeting_req = NULL;
int col_index = 0;
time_t temp_unix_time;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
if (rc == SQLITE_DONE) {
EM_DEBUG_EXCEPTION(" no Meeting request found...");
count = 0;
ret = false;
- error= EMF_ERROR_DATA_NOT_FOUND;
+ error= EMAIL_ERROR_DATA_NOT_FOUND;
goto FINISH_OFF;
}
- if (!(p_temp_meeting_req = (emf_meeting_request_t*)malloc(sizeof(emf_meeting_request_t)))) {
+ if (!(p_temp_meeting_req = (email_meeting_request_t*)malloc(sizeof(email_meeting_request_t)))) {
EM_DEBUG_EXCEPTION(" malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
- memset(p_temp_meeting_req, 0x00, sizeof(emf_meeting_request_t));
+ memset(p_temp_meeting_req, 0x00, sizeof(email_meeting_request_t));
col_index = 0;
hStmt = NULL;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
}
-INTERNAL_FUNC int emstorage_update_meeting_request(emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_update_meeting_request(email_meeting_request_t* meeting_req, int transaction, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("meeting_req[%p], transaction[%d], err_code[%p]", meeting_req, transaction, err_code);
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int rc;
DB_STMT hStmt = NULL;
char sql_query_string[QUERY_SIZE] = {0, };
if (!meeting_req) {
EM_DEBUG_EXCEPTION("Invalid Parameter!");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
EM_DEBUG_LOG("SQL(%s)", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/*
EM_DEBUG_LOG(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
ret = true;
if (rc != SQLITE_OK) {
EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
return ret;
}
-
-INTERNAL_FUNC int emstorage_change_meeting_request_field(int account_id, char *mailbox_name, emf_mail_change_type_t type, emf_meeting_request_t* meeting_req, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, int input_mailbox_id, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%s], type[%d], meeting_req[%p], transaction[%d], err_code[%p]", account_id, mailbox_name, type, meeting_req, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], input_mailbox_id[%d], transaction[%d], err_code[%p]", account_id, mail_id, input_mailbox_id, transaction, err_code);
- if (account_id <= 0 || !meeting_req || meeting_req->mail_id <= 0) {
- if (meeting_req)
- EM_DEBUG_EXCEPTION("mail_id[%d]", meeting_req->mail_id);
+ if (account_id < ALL_ACCOUNT || mail_id < 0) {
+ EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d]", account_id, mail_id);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;;
- }
-
- int rc;
- int ret = false;
- int error = EMF_ERROR_NONE;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
-
- int col_index = 0;
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
-
- switch (type) {
- case UPDATE_MAILBOX:
- EM_DEBUG_LOG(">>>>> UPDATE_MAILBOX : Move");
- if (!mailbox_name) {
- EM_DEBUG_EXCEPTION(" mailbox_name[%p]", mailbox_name);
- error = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_meeting_tbl SET mailbox_name = ? WHERE mail_id = %d", meeting_req->mail_id);
-
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- _bind_stmt_field_data_string(hStmt, col_index++, (char *)mailbox_name, 0, MAILBOX_LEN_IN_MAIL_MEETING_TBL);
- break;
-
- default:
- EM_DEBUG_LOG("type[%d]", type);
-
- error = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG("Query = [%s]", sql_query_string);
-
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- ret = true;
-
-FINISH_OFF:
- if (hStmt != NULL) {
- EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
- _DISCONNECT_DB;
-
- if (err_code != NULL)
- *err_code = error;
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-
-INTERNAL_FUNC int emstorage_change_meeting_request_mailbox(int account_id, char *old_mailbox_name, char *new_mailbox_name, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p], transaction[%d], err_code[%p]", account_id, old_mailbox_name, new_mailbox_name, transaction, err_code);
-
- if (account_id < FIRST_ACCOUNT_ID || !old_mailbox_name || !new_mailbox_name) {
- EM_DEBUG_EXCEPTION("account_id[%d], old_mailbox_name[%p], new_mailbox_name[%p]", account_id, old_mailbox_name, new_mailbox_name);
-
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
- return false;
- }
-
- int rc;
- int ret = true;
- int error = EMF_ERROR_NONE;
- char sql_query_string[QUERY_SIZE] = {0, };
-
- sqlite3 *local_db_handle = emstorage_get_db_connection();
-
- EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
-
- EM_DEBUG_LOG("Update mailbox_name - searching by mailbox_name name");
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_meeting_tbl SET"
- " mailbox_name = '%s'"
- " WHERE account_id = %d"
- " AND mailbox_name = '%s'"
- , new_mailbox_name
- , account_id
- , old_mailbox_name);
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
- ("sqlite3_exec fail:%d", rc));
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- rc = sqlite3_changes(local_db_handle);
- if (rc == 0)
- EM_DEBUG_EXCEPTION("NO meetring request found...");
-
- ret = true;
-
-FINISH_OFF:
-
- EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
- _DISCONNECT_DB;
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-
-INTERNAL_FUNC int emstorage_delete_meeting_request(int account_id, int mail_id, char *mailbox_name, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], mailbox_name[%s], transaction[%d], err_code[%p]", account_id, mail_id, mailbox_name, transaction, err_code);
-
- if (account_id < ALL_ACCOUNT || mail_id < 0) {
- EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d]", account_id, mail_id);
-
- if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc;
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int and = false;
char sql_query_string[QUERY_SIZE] = {0, };
SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mail_id = %d", (and ? "AND" : "WHERE"), mail_id);
and = true;
}
- if (mailbox_name) { /* NULL means all mailbox_name */
- SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_name = '%s'", (and ? "AND" : "WHERE"), mailbox_name);
+ if (input_mailbox_id > 0) { /* 0 means all mailbox_id */
+ SNPRINTF(sql_query_string + strlen(sql_query_string), sizeof(sql_query_string)-(strlen(sql_query_string)+1), " %s mailbox_id = '%d'", (and ? "AND" : "WHERE"), input_mailbox_id);
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
return ret;
}
-INTERNAL_FUNC int emstorage_free_meeting_request(emf_meeting_request_t **meeting_req, int count, int *err_code)
+
+INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeting_req)
{
- EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d], err_code[%p]", meeting_req, count, err_code);
+ EM_DEBUG_FUNC_BEGIN();
- int ret = false;
- int error = EMF_ERROR_NONE;
- int i = 0;
- emf_meeting_request_t *cursor;
-
- if (count > 0) {
- if (!meeting_req || !*meeting_req) {
- EM_DEBUG_EXCEPTION("meeting_req[%p], count[%d]", meeting_req, count);
- error = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
+ if (!meeting_req ) {
+ EM_DEBUG_EXCEPTION("NULL PARAM");
+ return;
}
- for (i = 0; i < count; i++) {
- cursor = (*meeting_req) + i;
- EM_SAFE_FREE(cursor->location);
- EM_SAFE_FREE(cursor->global_object_id);
- }
- EM_SAFE_FREE(*meeting_req);
- }
-
- ret = true;
-
-FINISH_OFF:
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
+ EM_SAFE_FREE(meeting_req->location);
+ EM_SAFE_FREE(meeting_req->global_object_id);
+ EM_DEBUG_FUNC_END();
}
-INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, char *mailbox_name, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
+INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_name [%p], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, mailbox_name, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code);
+ EM_DEBUG_FUNC_BEGIN("account_id [%d], input_mailbox_id [%d], mail_slot_size [%d], mail_id_list [%p], mail_id_count [%p], transaction [%d], err_code [%p]", account_id, input_mailbox_id, mail_slot_size, mail_id_list, mail_id_count, transaction, err_code);
EM_PROFILE_BEGIN(profile_emstorage_get_overflowed_mail_id_list);
char sql_query_string[QUERY_SIZE] = {0, };
char **result = NULL;
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int counter = 0, col_index = 0;
int result_mail_id_count = 0;
int *result_mail_id_list = NULL;
- if (!mailbox_name || !mail_id_list || !mail_id_count || account_id < 1) {
+ if (input_mailbox_id <= 0 || !mail_id_list || !mail_id_count || account_id < 1) {
EM_DEBUG_EXCEPTION("Invalid Parameter");
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_name = '%s' ORDER BY date_time DESC LIMIT %d, 10000", account_id, mailbox_name, mail_slot_size);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND mailbox_id = %d ORDER BY date_time DESC LIMIT %d, 10000", account_id, input_mailbox_id, mail_slot_size);
EM_DEBUG_LOG("query[%s].", sql_query_string);
EMSTORAGE_START_READ_TRANSACTION(transaction);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (!result_mail_id_count) {
EM_DEBUG_LOG("No mail found...");
ret = false;
- error= EMF_ERROR_MAIL_NOT_FOUND;
+ error= EMAIL_ERROR_MAIL_NOT_FOUND;
goto FINISH_OFF;
}
- EM_DEBUG_LOG("There are [%d] overflowed mails in mailbox_name [%s]", result_mail_id_count, mailbox_name);
+ EM_DEBUG_LOG("There are [%d] overflowed mails in mailbox_id [%d]", result_mail_id_count, input_mailbox_id);
if (!(result_mail_id_list = (int *)malloc(sizeof(int) * result_mail_id_count))) {
EM_DEBUG_EXCEPTION("malloc for result_mail_id_list failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
sqlite3_free_table(result);
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN("mail_id[%d], thread_id[%p], err_code[%p]", mail_id, thread_id, err_code);
int rc = -1, ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
char **result;
int result_count = 0;
if (mail_id == 0 || thread_id == NULL) {
EM_DEBUG_EXCEPTION("Invalid Parameter");
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
/* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (!result_count) {
EM_DEBUG_EXCEPTION("No mail found...");
ret = false;
- err= EMF_ERROR_MAIL_NOT_FOUND;
+ err= EMAIL_ERROR_MAIL_NOT_FOUND;
/* sqlite3_free_table(result); */
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN("account_id [%d], thread_id[%d], latest_mail_id [%d], thread_item_count[%d], err_code[%p]", account_id, thread_id, latest_mail_id, thread_item_count, err_code);
int rc = -1, ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
char sql_query_string[QUERY_SIZE] = {0, };
char **result;
int result_count = 0;
if (thread_id == 0) {
EM_DEBUG_EXCEPTION("Invalid Parameter");
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
/* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG("result_count[%d]", result_count);
if (result_count == 0) {
EM_DEBUG_EXCEPTION("No mail found...");
ret = false;
- err= EMF_ERROR_MAIL_NOT_FOUND;
+ err= EMAIL_ERROR_MAIL_NOT_FOUND;
sqlite3_free_table(result);
goto FINISH_OFF;
}
EM_DEBUG_LOG("query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
/* } */
EM_DEBUG_LOG("query[%s]", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
ret = true;
}
-INTERNAL_FUNC void
-emstorage_flush_db_cache()
+INTERNAL_FUNC void emstorage_flush_db_cache()
{
sqlite3_release_memory(-1);
}
EM_DEBUG_LOG(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code);
int rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
DB_STMT hStmt = NULL;
char sql_query_string[8192] = { 0x00, };
int i = 0;
if (!local_activity) {
EM_DEBUG_EXCEPTION(" local_activity[%p], transaction[%d], err_code[%p]", local_activity, transaction, err_code);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMF_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
ret = true;
if (rc != SQLITE_OK) {
EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
- error = EMF_ERROR_DB_FAILURE;
+ error = EMAIL_ERROR_DB_FAILURE;
}
}
else {
EM_DEBUG_FUNC_BEGIN();
int i = 0, count = 0, rc = -1, ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
emstorage_activity_tbl_t *p_activity_tbl = NULL;
char sql_query_string[1024] = {0x00, };
char **result = NULL;
if (!select_num || !activity_list || account_id <= 0 || activityid < 0) {
EM_DEBUG_LOG(" select_num[%p], activity_list[%p] account_id [%d] activityid [%d] ", select_num, activity_list, account_id, activityid);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
if (!(p_activity_tbl = (emstorage_activity_tbl_t*)em_malloc(sizeof(emstorage_activity_tbl_t) * count))) {
EM_DEBUG_EXCEPTION(" em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
EM_DEBUG_FUNC_BEGIN();
int ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
int rc = -1;
char *sql = NULL;
char **result = NULL;
{
EM_DEBUG_EXCEPTION(" activity_id[%p]", activity_id);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
sql = "SELECT max(rowid) FROM mail_local_activity_tbl;";
/* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); n EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); */
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
if (NULL==result[1])
if (account_id <= 0|| NULL == activity_id_list || NULL == activity_id_count ||lowest_activity_type <=0 || highest_activity_type <= 0) {
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int ret = false;
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int i = 0, rc = -1, count = 0;
char sql_query_string[1024] = {0x00, };
int *activity_ids = NULL;
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMF_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
col_index = 1;
if (NULL == (activity_ids = (int *)em_malloc(sizeof(int) * count))) {
EM_DEBUG_EXCEPTION(" em_malloc failed...");
- error = EMF_ERROR_OUT_OF_MEMORY;
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
{
EM_DEBUG_FUNC_BEGIN();
- int error = EMF_ERROR_NONE;
+ int error = EMAIL_ERROR_NONE;
int ret = false;
EM_DEBUG_LOG(" activity_id_list [%p]", activity_id_list);
if (NULL == activity_id_list) {
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
else {
if (!local_activity) {
EM_DEBUG_EXCEPTION(" local_activity[%p] ", local_activity);
if (err_code != NULL)
- *err_code = EMF_ERROR_INVALID_PARAM;
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
return false;
}
int rc = -1, ret = false; /* Prevent_FIX */
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
int query_and = 0;
int query_where = 0;
char sql_query_string[8192] = { 0x00, };
EM_DEBUG_LOG(">>>>> Query [ %s ] ", sql_query_string);
EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMF_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
rc = sqlite3_changes(local_db_handle);
if (rc == 0) {
EM_DEBUG_EXCEPTION(" no (matched) mailbox_name found...");
- err = EMF_ERROR_MAILBOX_NOT_FOUND;
+ err = EMAIL_ERROR_MAILBOX_NOT_FOUND;
}
ret = true;
EM_DEBUG_LOG(" local_activity_list[%p], count[%d], err_code[%p]", local_activity_list, count, err_code);
int ret = false;
- int error = EMF_ERROR_INVALID_PARAM;
+ int error = EMAIL_ERROR_INVALID_PARAM;
if (count > 0) {
if (!local_activity_list || !*local_activity_list) {
EM_DEBUG_EXCEPTION(" local_activity_list[%p], count[%d]", local_activity_list, count);
- error = EMF_ERROR_INVALID_PARAM;
+ error = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
}
#endif /* __FEATURE_LOCAL_ACTIVITY__ */
+static char *_mail_field_name_list[] = {
+ "mail_id",
+ "account_id",
+ "mailbox_id",
+ "mailbox_name",
+ "mailbox_type",
+ "subject",
+ "date_time",
+ "server_mail_status",
+ "server_mailbox_name",
+ "server_mail_id",
+ "message_id",
+ "full_address_from",
+ "full_address_to",
+ "full_address_cc",
+ "full_address_bcc",
+ "body_download_status",
+ "file_path_plain",
+ "file_path_html",
+ "file_size",
+ "flags_seen_field",
+ "flags_deleted_field",
+ "flags_flagged_field",
+ "flags_answered_field",
+ "flags_recent_field",
+ "flags_draft_field",
+ "flags_forwarded_field",
+ "drm_status",
+ "priority",
+ "save_status",
+ "lock_status",
+ "report_status",
+ "attachment_count",
+ "inline_content_count",
+ "thread_id",
+ "thread_item_count",
+ "preview_text",
+ "meeting_request_status",
+ "message_class",
+ "digest_type",
+ "smime_type"
+};
+
+static char*_get_mail_field_name_by_attribute_type(email_mail_attribute_type input_attribute_type)
+{
+ EM_DEBUG_FUNC_BEGIN("input_attribute_type [%d]", input_attribute_type);
+
+ if(input_attribute_type > EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS || input_attribute_type < 0) {
+ EM_DEBUG_EXCEPTION("Invalid input_attribute_type [%d]", input_attribute_type);
+ return NULL;
+ }
+
+ EM_DEBUG_FUNC_END("return [%s]", _mail_field_name_list[input_attribute_type]);
+ return _mail_field_name_list[input_attribute_type];
+}
+
+static int _get_attribute_type_by_mail_field_name(char *input_mail_field_name, email_mail_attribute_type *output_mail_attribute_type)
+{
+ EM_DEBUG_FUNC_BEGIN("input_mail_field_name [%p], output_mail_attribute_type [%p]", input_mail_field_name, output_mail_attribute_type);
+ int i = 0;
+ int err = EMAIL_ERROR_DATA_NOT_FOUND;
+
+ if(!input_mail_field_name || !output_mail_attribute_type) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ for (i = 0; i < EMAIL_MAIL_ATTRIBUTE_END; i++) {
+ if (EM_SAFE_STRCMP(input_mail_field_name, _mail_field_name_list[i]) == 0) {
+ *output_mail_attribute_type = i;
+ err = EMAIL_ERROR_NONE;
+ break;
+ }
+ }
+
+ EM_DEBUG_FUNC_END("found mail attribute type [%d]", (int)*output_mail_attribute_type);
+ return err;
+}
+
+static int _get_key_value_string_for_list_filter_rule(email_list_filter_rule_t *input_list_filter_rule,char **output_key_value_string)
+{
+ EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_key_value_string [%p]", input_list_filter_rule, output_key_value_string);
+
+ int ret = EMAIL_ERROR_NONE;
+ char key_value_string[QUERY_SIZE] = { 0, };
+ char *temp_key_value_1 = NULL;
+ char *temp_key_value_2 = NULL;
+
+ if(input_list_filter_rule == NULL || output_key_value_string == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ switch(input_list_filter_rule->target_attribute) {
+ case EMAIL_MAIL_ATTRIBUTE_MAIL_ID :
+ case EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID :
+ case EMAIL_MAIL_ATTRIBUTE_MAILBOX_ID :
+ case EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_BODY_DOWNLOAD_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN :
+ case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML :
+ case EMAIL_MAIL_ATTRIBUTE_FILE_SIZE :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_SEEN_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_DELETED_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_FLAGGED_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_ANSWERED_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_RECENT_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_DRAFT_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_FLAGS_FORWARDED_FIELD :
+ case EMAIL_MAIL_ATTRIBUTE_DRM_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_PRIORITY :
+ case EMAIL_MAIL_ATTRIBUTE_SAVE_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_LOCK_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_REPORT_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT :
+ case EMAIL_MAIL_ATTRIBUTE_INLINE_CONTENT_COUNT :
+ case EMAIL_MAIL_ATTRIBUTE_THREAD_ID :
+ case EMAIL_MAIL_ATTRIBUTE_THREAD_ITEM_COUNT :
+ case EMAIL_MAIL_ATTRIBUTE_MEETING_REQUEST_STATUS :
+ case EMAIL_MAIL_ATTRIBUTE_MESSAGE_CLASS :
+ case EMAIL_MAIL_ATTRIBUTE_DIGEST_TYPE :
+ case EMAIL_MAIL_ATTRIBUTE_SMIME_TYPE :
+ SNPRINTF(key_value_string, QUERY_SIZE, "%d", input_list_filter_rule->key_value.integer_type_value);
+ break;
+
+ case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME :
+ case EMAIL_MAIL_ATTRIBUTE_SUBJECT :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID :
+ case EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID :
+ case EMAIL_MAIL_ATTRIBUTE_FROM :
+ case EMAIL_MAIL_ATTRIBUTE_TO :
+ case EMAIL_MAIL_ATTRIBUTE_CC :
+ case EMAIL_MAIL_ATTRIBUTE_BCC :
+ case EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT :
+ if(input_list_filter_rule->key_value.string_type_value == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid string_type_value [%p]", input_list_filter_rule->key_value.string_type_value);
+ ret = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ temp_key_value_1 = input_list_filter_rule->key_value.string_type_value;
+
+ temp_key_value_2 = em_replace_all_string(temp_key_value_1, "_", "\\_");
+ temp_key_value_1 = em_replace_all_string(temp_key_value_2, "%", "\\%");
+
+ if(input_list_filter_rule->rule_type == EMAIL_LIST_FILTER_RULE_INCLUDE)
+ SNPRINTF(key_value_string, QUERY_SIZE, "\'%%%s%%\'", temp_key_value_1);
+ else
+ SNPRINTF(key_value_string, QUERY_SIZE, "\'%s\'", temp_key_value_1);
+ break;
+
+ case EMAIL_MAIL_ATTRIBUTE_DATE_TIME :
+ SNPRINTF(key_value_string, QUERY_SIZE, "%d", (int)input_list_filter_rule->key_value.datetime_type_value);
+ break;
+
+ default :
+ ret = EMAIL_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("Invalid target_attribute [%d]", input_list_filter_rule->target_attribute);
+ break;
+ }
+
+ if(ret == EMAIL_ERROR_NONE && strlen(key_value_string) > 0) {
+ *output_key_value_string = strdup(key_value_string);
+ }
+
+FINISH_OFF:
+
+ EM_SAFE_FREE(temp_key_value_1);
+ EM_SAFE_FREE(temp_key_value_2);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+static int _get_cert_password_file_name(int index, char *cert_password_file_name)
+{
+ EM_DEBUG_FUNC_BEGIN("index : [%d]", index);
+
+ if (index <= 0 || !cert_password_file_name) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ sprintf(cert_password_file_name, ".email_cert_%d", index);
+
+ EM_DEBUG_FUNC_END();
+ return EMAIL_ERROR_NONE;
+}
+#endif
+
+static int _make_filter_rule_string(email_list_filter_rule_t *input_list_filter_rule, char **output_string)
+{
+ EM_DEBUG_FUNC_BEGIN("input_list_filter_rule [%p], output_string [%p]", input_list_filter_rule, output_string);
+
+ int ret = EMAIL_ERROR_NONE;
+ int is_alpha = 0;
+ int length_field_name = 0;
+ int length_value = 0;
+ char result_rule_string[QUERY_SIZE] = { 0 , };
+ char *mod_field_name_string = NULL;
+ char *mod_value_string = NULL;
+ char *temp_field_name_string = NULL;
+ char *temp_key_value_string = NULL;
+
+ if(input_list_filter_rule == NULL || output_string == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ temp_field_name_string = _get_mail_field_name_by_attribute_type(input_list_filter_rule->target_attribute);
+
+ if(temp_field_name_string == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid target_attribute [%d]", input_list_filter_rule->target_attribute);
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ if( _get_key_value_string_for_list_filter_rule(input_list_filter_rule, &temp_key_value_string) != EMAIL_ERROR_NONE || temp_key_value_string == NULL) {
+ EM_DEBUG_EXCEPTION("_get_key_value_string_for_list_filter_rule failed");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ length_field_name = strlen(temp_field_name_string);
+ length_value = strlen(temp_key_value_string);
+
+ switch(input_list_filter_rule->target_attribute) {
+ case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME :
+ case EMAIL_MAIL_ATTRIBUTE_SUBJECT :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID :
+ case EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID :
+ case EMAIL_MAIL_ATTRIBUTE_FROM :
+ case EMAIL_MAIL_ATTRIBUTE_TO :
+ case EMAIL_MAIL_ATTRIBUTE_CC :
+ case EMAIL_MAIL_ATTRIBUTE_BCC :
+ case EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT :
+ is_alpha = 1;
+ break;
+ default :
+ is_alpha = 0;
+ break;
+ }
+
+ if(is_alpha == 1 && input_list_filter_rule->case_sensitivity == false) {
+ length_field_name += strlen("UPPER() ");
+ length_value += strlen("UPPER() ");
+ mod_field_name_string = em_malloc(sizeof(char) * length_field_name);
+ mod_value_string = em_malloc(sizeof(char) * length_value);
+ SNPRINTF(mod_field_name_string, length_field_name, "UPPER(%s)", temp_field_name_string);
+ SNPRINTF(mod_value_string, length_value, "UPPER(%s)", temp_key_value_string);
+ EM_SAFE_FREE(temp_key_value_string);
+ }
+ else {
+ mod_field_name_string = strdup(temp_field_name_string);
+ mod_value_string = temp_key_value_string;
+ }
+
+ switch (input_list_filter_rule->rule_type) {
+ case EMAIL_LIST_FILTER_RULE_EQUAL :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s = %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_NOT_EQUAL :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s = %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_LESS_THAN :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s < %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_GREATER_THAN :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s > %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_LESS_THAN_OR_EQUAL :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s <= %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_GREATER_THAN_OR_EQUAL :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s >= %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_INCLUDE :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s LIKE %s ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_IN :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s IN (%s) ", mod_field_name_string, mod_value_string);
+ break;
+ case EMAIL_LIST_FILTER_RULE_NOT_IN :
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s NOT IN (%s) ", mod_field_name_string, mod_value_string);
+ break;
+ default :
+ EM_DEBUG_EXCEPTION("Invalid rule_type [%d]", input_list_filter_rule->rule_type);
+ ret = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *output_string = strdup(result_rule_string);
+
+FINISH_OFF:
+ EM_SAFE_FREE(mod_field_name_string);
+ EM_SAFE_FREE(mod_value_string);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+static int _make_order_rule_string(email_list_sorting_rule_t *input_sorting_rule, char **output_string) {
+ EM_DEBUG_FUNC_BEGIN("input_sorting_rule [%p], output_string [%p]", input_sorting_rule, output_string);
+
+ char result_rule_string[QUERY_SIZE] = { 0 , };
+ int ret = EMAIL_ERROR_NONE;
+
+ if(input_sorting_rule->force_boolean_check) {
+ SNPRINTF(result_rule_string, QUERY_SIZE, "%s = 0 ", _get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
+ }
+ else
+ EM_SAFE_STRCPY(result_rule_string, _get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute));
+
+ switch (input_sorting_rule->sort_order) {
+ case EMAIL_SORT_ORDER_ASCEND :
+ EM_SAFE_STRCAT(result_rule_string, " ASC ");
+ break;
+
+ case EMAIL_SORT_ORDER_DESCEND :
+ EM_SAFE_STRCAT(result_rule_string, " DESC ");
+ break;
+
+ default :
+ EM_DEBUG_EXCEPTION("Invalid sort_order [%d]", input_sorting_rule->sort_order);
+ ret = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ *output_string = strdup(result_rule_string);
+
+FINISH_OFF:
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, char **output_conditional_clause)
+{
+ EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d], input_sorting_rule_list[%p], input_sorting_rule_count [%d], input_start_index [%d], input_limit_count [%d], output_conditional_clause [%p]", input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, output_conditional_clause);
+ int ret = EMAIL_ERROR_NONE;
+ int i = 0;
+ char conditional_clause_string[QUERY_SIZE] = {0, };
+ char *result_string_for_a_item = NULL;
+
+ if ( (input_filter_count > 0 && !input_filter_list) || (input_sorting_rule_count > 0 && !input_sorting_rule_list) || output_conditional_clause == NULL) {
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ return EMAIL_ERROR_INVALID_PARAM;
+ }
+
+ if(input_filter_count > 0) {
+ strcpy(conditional_clause_string, " WHERE ");
+
+ for ( i = 0; i < input_filter_count; i++) {
+ switch (input_filter_list[i].list_filter_item_type) {
+ case EMAIL_LIST_FILTER_ITEM_RULE :
+ EM_DEBUG_LOG("[%d]list_filter_item_type is EMAIL_LIST_FILTER_ITEM_RULE", i);
+ _make_filter_rule_string(&(input_filter_list[i].list_filter_item.rule), &result_string_for_a_item);
+ break;
+
+ case EMAIL_LIST_FILTER_ITEM_OPERATOR :
+ EM_DEBUG_LOG("[%d]list_filter_item_type is EMAIL_LIST_FILTER_ITEM_OPERATOR", i);
+ switch(input_filter_list[i].list_filter_item.operator_type) {
+ case EMAIL_LIST_FILTER_OPERATOR_AND :
+ result_string_for_a_item = strdup("AND ");
+ break;
+ case EMAIL_LIST_FILTER_OPERATOR_OR :
+ result_string_for_a_item = strdup("OR ");
+ break;
+ case EMAIL_LIST_FILTER_OPERATOR_LEFT_PARENTHESIS :
+ result_string_for_a_item = strdup(" (");
+ break;
+ case EMAIL_LIST_FILTER_OPERATOR_RIGHT_PARENTHESIS :
+ result_string_for_a_item = strdup(") ");
+ break;
+ }
+ break;
+
+ default :
+ EM_DEBUG_EXCEPTION("Invalid list_filter_item_type [%d]", input_filter_list[i].list_filter_item_type);
+ ret = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if(result_string_for_a_item == NULL) {
+ EM_DEBUG_EXCEPTION("result_string_for_a_item is null");
+ ret = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ if(strlen(conditional_clause_string) + strlen(result_string_for_a_item) >= QUERY_SIZE) {
+ EM_DEBUG_EXCEPTION("Query is too long");
+ ret = EMAIL_ERROR_DATA_TOO_LONG;
+ goto FINISH_OFF;
+ }
+ strcat(conditional_clause_string, result_string_for_a_item);
+ EM_SAFE_FREE(result_string_for_a_item);
+ }
+ }
+
+ if(input_sorting_rule_count > 0) {
+ strcat(conditional_clause_string, "ORDER BY ");
+
+ for ( i = 0; i < input_sorting_rule_count; i++) {
+ if( (ret = _make_order_rule_string(&input_sorting_rule_list[i], &result_string_for_a_item)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("_make_order_rule_string failed. [%d]", ret);
+ goto FINISH_OFF;
+ }
+ if(i > 0)
+ strcat(conditional_clause_string, ", ");
+ strcat(conditional_clause_string, result_string_for_a_item);
+ EM_SAFE_FREE(result_string_for_a_item);
+ }
+ }
+
+ *output_conditional_clause = strdup(conditional_clause_string);
+
+FINISH_OFF:
+ EM_SAFE_FREE(result_string_for_a_item);
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count)
+{
+ EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d]", input_filter_list, input_filter_count);
+ int err = EMAIL_ERROR_NONE;
+ int i = 0;
+ email_list_filter_t *temp_filter_list = NULL;
+
+ EM_IF_NULL_RETURN_VALUE(input_filter_list, EMAIL_ERROR_INVALID_PARAM);
+
+ for ( i = 0; i < input_filter_count; i++) {
+ temp_filter_list = (*input_filter_list) + i;
+ if(temp_filter_list && temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE) {
+ switch(temp_filter_list->list_filter_item.rule.target_attribute) {
+ case EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME :
+ case EMAIL_MAIL_ATTRIBUTE_SUBJECT :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAILBOX_NAME :
+ case EMAIL_MAIL_ATTRIBUTE_SERVER_MAIL_ID :
+ case EMAIL_MAIL_ATTRIBUTE_MESSAGE_ID :
+ case EMAIL_MAIL_ATTRIBUTE_FROM :
+ case EMAIL_MAIL_ATTRIBUTE_TO :
+ case EMAIL_MAIL_ATTRIBUTE_CC :
+ case EMAIL_MAIL_ATTRIBUTE_BCC :
+ case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_PLAIN :
+ case EMAIL_MAIL_ATTRIBUTE_FILE_PATH_HTML :
+ case EMAIL_MAIL_ATTRIBUTE_PREVIEW_TEXT :
+ EM_SAFE_FREE(temp_filter_list->list_filter_item.rule.key_value.string_type_value);
+ break;
+ default :
+ break;
+ }
+ }
+ }
+
+ free(*input_filter_list);
+ *input_filter_list = NULL;
+
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
+}
+
+INTERNAL_FUNC int emstorage_add_certificate(emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
+
+ if (!certificate) {
+ EM_DEBUG_EXCEPTION("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EMAIL_ERROR_NONE;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+
+ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ char *sql = "SELECT max(rowid) FROM mail_certificate_tbl;";
+ char **result = NULL;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ if (NULL==result[1]) rc = 1;
+ else rc = atoi(result[1])+1;
+ sqlite3_free_table(result);
+
+ certificate->certificate_id = rc;
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ if ((error = _get_cert_password_file_name(certificate->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+#endif
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "INSERT INTO mail_certificate_tbl VALUES "
+ "( "
+ " ? " /* Index of certificate */
+ " , ? " /* Select the account */
+ " , ? " /* Year of issue */
+ " , ? " /* Month of issue */
+ " , ? " /* Day of issue */
+ " , ? " /* Year of expiration */
+ " , ? " /* Month of expiration */
+ " , ? " /* Day of expiration */
+ " , ? " /* Organization of issue */
+ " , ? " /* Email address */
+ " , ? " /* Subject of certificate */
+ " , ? " /* Name of saved certificate */
+ ") ");
+
+
+ /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EM_DEBUG_LOG(">>>> SQL STMT [ %s ] ", sql_query_string);
+ _bind_stmt_field_data_int(hStmt, CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->certificate_id);
+ _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year);
+ _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month);
+ _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day);
+ _bind_stmt_field_data_int(hStmt, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_year);
+ _bind_stmt_field_data_int(hStmt, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_month);
+ _bind_stmt_field_data_int(hStmt, EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_day);
+ _bind_stmt_field_data_string(hStmt, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_organization_name, 0, ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
+ /* rc = sqlite3_step(hStmt); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ if (ssm_write_buffer(certificate->password, strlen(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name);
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+#endif
+ ret = true;
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ if (!emstorage_notify_storage_event(NOTI_CERTIFICATE_ADD, certificate->certificate_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION("emstorage_notify_storage_event(NOTI_CERTIFICATE_ADD] : Notification failed");
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG("sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+ else
+ EM_DEBUG_LOG("hStmt is NULL!!!");
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("certificate_list[%p], count[%d], err_code[%p]", certificate_list, count, err_code);
+
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+
+ if (count > 0) {
+ if (!certificate_list || !*certificate_list) {
+ EM_DEBUG_EXCEPTION("certificate_list[%p], count[%d]", certificate_list, count);
+ error = EMAIL_ERROR_INVALID_PARAM;
+ goto FINISH_OFF;
+ }
+
+ emstorage_certificate_tbl_t *p = *certificate_list;
+ int i = 0;
+
+ for (; i < count; i++) {
+ EM_SAFE_FREE(p[i].issue_organization_name);
+ EM_SAFE_FREE(p[i].email_address);
+ EM_SAFE_FREE(p[i].subject_str);
+ EM_SAFE_FREE(p[i].filepath);
+ EM_SAFE_FREE(p[i].password);
+ }
+
+ EM_SAFE_FREE(p);
+ *certificate_list = NULL;
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_certificate_list(int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN();
+
+ int i = 0, count = 0, rc = -1, ret = false;
+ int error = EMAIL_ERROR_NONE;
+ emstorage_certificate_tbl_t *p_data_tbl = NULL;
+
+ DB_STMT hStmt = NULL;
+
+ if (!select_num || !certificate_list) {
+ EM_DEBUG_EXCEPTION("select_num[%p], account_list[%p]", select_num, certificate_list);
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+ EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+ char sql_query_string[QUERY_SIZE] = {0, };
+ char *sql = "SELECT count(*) FROM mail_certificate_tbl;";
+ char **result;
+
+ /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
+
+ count = atoi(result[1]);
+ sqlite3_free_table(result);
+
+ if (!count) {
+ EM_DEBUG_EXCEPTION("no account found...");
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ ret = true;
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("count = %d", rc);
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_certificate_tbl ORDER BY account_id");
+
+ /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+
+ EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* rc = sqlite3_step(hStmt); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no account found...");
+
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ count = 0;
+ ret = true;
+ goto FINISH_OFF;
+ }
+
+ if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t) * count))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+ memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t) * count);
+ for (i = 0; i < count; i++) {
+ /* get recordset */
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ if (with_password == true) {
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ /* get password from the secure storage */
+ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+
+ EM_SAFE_FREE(p_data_tbl[i].password);
+
+ /* get password file name */
+ if ((error = _get_cert_password_file_name(p_data_tbl[i].certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* read password from secure storage */
+ if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl[i].password))) < 0) {
+ EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("recv_password_file_name[%s], password[%s]", cert_password_file_name, p_data_tbl[i].password);
+#endif
+ }
+
+ /* rc = sqlite3_step(hStmt); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i, rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ }
+
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true) {
+ *certificate_list = p_data_tbl;
+ *select_num = count;
+ EM_DEBUG_LOG("COUNT : %d", count);
+ }
+ else if (p_data_tbl != NULL)
+ emstorage_free_certificate(&p_data_tbl, count, NULL);
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG("Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ hStmt = NULL;
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("email_address[%s], certificate[%p], transaction[%d], err_code[%p]", email_address, certificate, transaction, err_code);
+
+ if (!certificate) {
+ EM_DEBUG_EXCEPTION("email_address[%s], certificate[%p]", email_address, certificate);
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ emstorage_certificate_tbl_t *p_data_tbl = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int rc = -1;
+ int sql_len = 0;
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+ EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+ /* Make query string */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
+ sql_len = strlen(sql_query_string);
+
+ /* dummy value, FROM WHERE clause */
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE email_address = '%s'", email_address);
+
+ /* FROM clause */
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+ /* execute a sql and count rows */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched certificate found...");
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ /* Assign query result to structure */
+ if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t));
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
+
+ if (with_password) {
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ /* get password file name */
+ if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* read password from secure storage */
+ if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("cert_password_file_name[%s], password[%s]", cert_password_file_name, p_data_tbl->password);
+#endif
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *certificate = p_data_tbl;
+ else {
+ if (p_data_tbl)
+ emstorage_free_certificate((emstorage_certificate_tbl_t **)&p_data_tbl, 1, NULL);
+ }
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_get_certificate_by_index(int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("index[%d], certificate[%p], transaction[%d], err_code[%p]", index, certificate, transaction, err_code);
+
+ if (!certificate) {
+ EM_DEBUG_EXCEPTION("index[%d], account[%p]", index, certificate);
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int ret = false;
+ int error = EMAIL_ERROR_NONE;
+ emstorage_certificate_tbl_t *p_data_tbl = NULL;
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+ int rc = -1;
+ int sql_len = 0;
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+ EMSTORAGE_START_READ_TRANSACTION(transaction);
+
+ /* Make query string */
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
+ sql_len = strlen(sql_query_string);
+
+ /* dummy value, FROM WHERE clause */
+ SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE certificate_id = %d", index);
+
+ /* FROM clause */
+ EM_DEBUG_LOG("query = [%s]", sql_query_string);
+
+ /* execute a sql and count rows */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ if (rc == SQLITE_DONE) {
+ EM_DEBUG_EXCEPTION("no matched certificate found...");
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+ /* Assign query result to structure */
+ if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t)))) {
+ EM_DEBUG_EXCEPTION("malloc failed...");
+ error = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t));
+
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
+ _get_stmt_field_data_string(hStmt, &(p_data_tbl->filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
+
+ if (with_password) {
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ /* get password file name */
+ if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* read password from secure storage */
+ if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed...");
+ goto FINISH_OFF;
+ }
+ EM_DEBUG_LOG("cert_password_file_name[%s], password[%s]", cert_password_file_name, p_data_tbl->password);
+#endif
+ }
+ ret = true;
+
+FINISH_OFF:
+ if (ret == true)
+ *certificate = p_data_tbl;
+ else {
+ if (p_data_tbl)
+ emstorage_free_certificate((emstorage_certificate_tbl_t **)&p_data_tbl, 1, NULL);
+ }
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_EXCEPTION("sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_delete_certificate(int certificate_id, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("certificate_id[%d], transaction[%d], err_code[%p]", certificate_id, transaction, err_code);
+
+ if (certificate_id < 1) {
+ EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id);
+
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int rc = -1, ret = false;
+ int error = EMAIL_ERROR_NONE;
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ /* TODO : delete password files - file names can be obtained from db or a rule that makes a name */
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+ /* get password file name */
+ if ((error = _get_cert_password_file_name(certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+#endif
+ /* delete from db */
+ memset(sql_query_string, 0x00, sizeof(sql_query_string));
+ SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_certificate_tbl WHERE certificate_id = %d", certificate_id);
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, sql_query_string, NULL, NULL, NULL), rc);
+ EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ ("sqlite3_exec fail:%d", rc));
+ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) exec fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ /* validate account existence */
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched certificate found...");
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ /* delete from secure storage */
+ if (ssm_delete_file(cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION(" ssm_delete_file failed -cert password : file[%s]", cert_password_file_name);
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+#endif
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
+
+INTERNAL_FUNC int emstorage_update_certificate(int certificate_id, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
+{
+ EM_DEBUG_FUNC_BEGIN("certificate_id[%d], certificate[%p], transaction[%d], err_code[%p]", certificate_id, certificate, transaction, err_code);
+
+ if (certificate_id < 1) {
+ EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id);
+
+ if (err_code != NULL)
+ *err_code = EMAIL_ERROR_INVALID_PARAM;
+ return false;
+ }
+
+ int error = EMAIL_ERROR_NONE;
+ int rc, ret = false;
+
+ DB_STMT hStmt = NULL;
+ char sql_query_string[QUERY_SIZE] = {0, };
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
+#endif
+ sqlite3 *local_db_handle = emstorage_get_db_connection();
+ EMSTORAGE_START_WRITE_TRANSACTION(transaction, error);
+
+ SNPRINTF(sql_query_string, sizeof(sql_query_string),
+ "UPDATE mail_certificate_tbl SET"
+ " issue_year = ?"
+ ", issue_month = ?" /* Index of certificate */
+ ", issue_day = ?" /* Select the account */
+ ", expiration_year = ?" /* Year of issue */
+ ", expiration_month = ?" /* Month of issue */
+ ", expiration_day = ?" /* Day of issue */
+ ", issue_organization_name = ?" /* Year of expiration */
+ ", email_address = ?" /* Month of expiration */
+ ", subject_str = ?" /* Day of expiration */
+ ", filepath = ?" /* Organization of issue */
+ ", password = ?"
+ " WHERE certificate_id = ?");
+
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, strlen(sql_query_string), &hStmt, NULL), rc);
+ EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
+ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
+
+ _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year);
+ _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month);
+ _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day);
+ _bind_stmt_field_data_int(hStmt, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_year);
+ _bind_stmt_field_data_int(hStmt, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_month);
+ _bind_stmt_field_data_int(hStmt, EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_day);
+ _bind_stmt_field_data_string(hStmt, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_organization_name, 0, ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL);
+ _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
+
+ /* rc = sqlite3_step(hStmt); */
+ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
+ EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
+ ("sqlite3_step fail:%d", rc));
+
+ /* validate account existence */
+ rc = sqlite3_changes(local_db_handle);
+ if (rc == 0) {
+ EM_DEBUG_EXCEPTION(" no matched account found...");
+
+ error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
+ goto FINISH_OFF;
+ }
+
+#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
+ /* get password file name */
+ if ((error = _get_cert_password_file_name(certificate->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
+ goto FINISH_OFF;
+ }
+
+ /* save passwords to the secure storage */
+ if (ssm_write_buffer(certificate->password, strlen(certificate->password), cert_password_file_name, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
+ EM_DEBUG_EXCEPTION("ssm_write_buffer failed - Private certificate password : [%s]", cert_password_file_name);
+ error = EMAIL_ERROR_SYSTEM_FAILURE;
+ goto FINISH_OFF;
+ }
+#endif
+ if (!emstorage_notify_storage_event(NOTI_CERTIFICATE_UPDATE, certificate->certificate_id, 0, NULL, 0))
+ EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event[ NOTI_CERTIFICATE_UPDATE] : Notification Failed >>> ");
+
+ ret = true;
+
+FINISH_OFF:
+
+ if (hStmt != NULL) {
+ EM_DEBUG_LOG(" Before sqlite3_finalize hStmt = %p", hStmt);
+
+ rc = sqlite3_finalize(hStmt);
+ if (rc != SQLITE_OK) {
+ EM_DEBUG_LOG(" sqlite3_finalize failed - %d", rc);
+ error = EMAIL_ERROR_DB_FAILURE;
+ }
+ }
+
+ EMSTORAGE_FINISH_WRITE_TRANSACTION(transaction, ret, error);
+
+ _DISCONNECT_DB;
+
+ if (err_code != NULL)
+ *err_code = error;
+
+ EM_DEBUG_FUNC_END("ret [%d]", ret);
+ return ret;
+}
/*EOF*/