* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
-*
+*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* File : email-core-account.c
* Desc : Account Management
*
- * Auth : Kyuho Jo
+ * Auth : Kyuho Jo
*
- * History :
+ * History :
* 2010.08.25 : created
*****************************************************************************/
#include <stdio.h>
#include "email-core-utils.h"
#include "email-core-event.h"
#include "email-core-global.h"
-#include "email-core-account.h"
+#include "email-core-account.h"
#include "email-core-mailbox.h"
#include "email-core-imap-mailbox.h"
-#ifdef __FEATURE_USING_MY_ACCOUNT__
-#include "account.h"
-#endif /* __FEATURE_USING_MY_ACCOUNT__ */
-
-char *g_default_mbox_alias[MAILBOX_COUNT] =
+char *g_default_mbox_alias[MAILBOX_COUNT] =
{
- EMF_INBOX_DISPLAY_NAME,
- EMF_DRAFTBOX_DISPLAY_NAME,
- EMF_OUTBOX_DISPLAY_NAME,
- EMF_SENTBOX_DISPLAY_NAME,
- EMF_TRASH_DISPLAY_NAME,
- EMF_SPAMBOX_DISPLAY_NAME,
+ EMAIL_INBOX_DISPLAY_NAME,
+ EMAIL_DRAFTBOX_DISPLAY_NAME,
+ EMAIL_OUTBOX_DISPLAY_NAME,
+ EMAIL_SENTBOX_DISPLAY_NAME,
+ EMAIL_TRASH_DISPLAY_NAME,
+ EMAIL_SPAMBOX_DISPLAY_NAME,
};
-char *g_default_mbox_name[MAILBOX_COUNT] =
+char *g_default_mbox_name[MAILBOX_COUNT] =
{
- EMF_INBOX_NAME,
- EMF_DRAFTBOX_NAME,
- EMF_OUTBOX_NAME,
- EMF_SENTBOX_NAME,
- EMF_TRASH_DISPLAY_NAME,
- EMF_SPAMBOX_NAME,
+ EMAIL_INBOX_NAME,
+ EMAIL_DRAFTBOX_NAME,
+ EMAIL_OUTBOX_NAME,
+ EMAIL_SENTBOX_NAME,
+ EMAIL_TRASH_DISPLAY_NAME,
+ EMAIL_SPAMBOX_NAME,
};
-emf_mailbox_type_e g_default_mbox_type[MAILBOX_COUNT] =
+email_mailbox_type_e g_default_mbox_type[MAILBOX_COUNT] =
{
- EMF_MAILBOX_TYPE_INBOX,
- EMF_MAILBOX_TYPE_DRAFT,
- EMF_MAILBOX_TYPE_OUTBOX,
- EMF_MAILBOX_TYPE_SENTBOX,
- EMF_MAILBOX_TYPE_TRASH,
- EMF_MAILBOX_TYPE_SPAMBOX,
+ EMAIL_MAILBOX_TYPE_INBOX,
+ EMAIL_MAILBOX_TYPE_DRAFT,
+ EMAIL_MAILBOX_TYPE_OUTBOX,
+ EMAIL_MAILBOX_TYPE_SENTBOX,
+ EMAIL_MAILBOX_TYPE_TRASH,
+ EMAIL_MAILBOX_TYPE_SPAMBOX,
};
-INTERNAL_FUNC emf_account_t* emcore_get_account_reference(int account_id)
+INTERNAL_FUNC email_account_t* emcore_get_account_reference(int account_id)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
EM_PROFILE_BEGIN(profile_emcore_get_account_reference);
- emf_account_list_t **p;
+ email_account_list_t **p;
if (account_id == NEW_ACCOUNT_ID)
return emcore_get_new_account_reference();
- if (account_id > 0) {
+ if (account_id > 0) {
p = &g_account_list;
while (*p) {
if ((*p)->account->account_id == account_id)
while (*p) {
if ((*p)->account->account_id == account_id)
return ((*p)->account);
-
+
p = &(*p)->next;
}
}
}
-
+
EM_PROFILE_END(profile_emcore_get_account_reference);
EM_DEBUG_FUNC_END();
return NULL;
}
-INTERNAL_FUNC int emcore_validate_account_with_account_info(emf_account_t *account, int *err_code)
+INTERNAL_FUNC int emcore_validate_account_with_account_info(email_account_t *account, int *err_code)
{
- EM_DEBUG_FUNC_BEGIN("account[%p], err_code[%p], receiving_server_addr [%s]", account, err_code, account->receiving_server_addr);
+ EM_DEBUG_FUNC_BEGIN("account[%p], err_code[%p], incoming_server_address [%s]", account, err_code, account->incoming_server_address);
int ret = false;
- int err = EMF_ERROR_NONE;
- emf_session_t *session = NULL;
+ int err = EMAIL_ERROR_NONE;
+ email_session_t *session = NULL;
SENDSTREAM *stream = NULL;
MAILSTREAM *tmp_stream = NULL;
- if (!emcore_check_thread_status()) {
- err = EMF_ERROR_CANCELLED;
+ if (!emcore_check_thread_status()) {
+ err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
}
EM_DEBUG_LOG("Network available");
- if (!emcore_check_thread_status()) {
- err = EMF_ERROR_CANCELLED;
+ if (!emcore_check_thread_status()) {
+ err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
- if (!emcore_get_empty_session(&session)) {
+ if (!emcore_get_empty_session(&session)) {
EM_DEBUG_EXCEPTION("emcore_get_empty_session failed...");
- err = EMF_ERROR_SESSION_NOT_FOUND;
+ err = EMAIL_ERROR_SESSION_NOT_FOUND;
goto FINISH_OFF;
}
-#ifdef _SMTP_ACCOUNT_VALIDATION_
+#ifdef _SMTP_ACCOUNT_VALIDATION_
/* validate connection for smt */
EM_DEBUG_LOG("Validate connection for SMTP");
if (!emcore_check_thread_status()) {
- err = EMF_ERROR_CANCELLED;
+ err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
if (!emcore_connect_to_remote_mailbox_with_account_info(account, (char *)ENCODED_PATH_SMTP, (void **)&stream, &err) || !stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed 1 - %d", err);
- if (EMF_ERROR_AUTHENTICATE == err || EMF_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
+ if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed : Login or Authentication fail 1- %d", err);
goto FINISH_OFF;
}
- if (account->sending_security == 0x01) /* 0x01 == ss */ {
+ if (account->outgoing_server_secure_connection == 0x01) /* 0x01 == ss */ {
/* retry with tl */
EM_DEBUG_LOG("Retry with TLS");
- account->sending_security = 0x02; /* 0x02 == tl */
+ account->outgoing_server_secure_connection = 0x02; /* 0x02 == tl */
if (!emcore_check_thread_status()) {
- err = EMF_ERROR_CANCELLED;
+ err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
-
+
if (!emcore_connect_to_remote_mailbox_with_account_info(account, (char *)ENCODED_PATH_SMTP, (void **)&stream, &err) || !stream) {
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed 2 - %d", err);
- if (EMF_ERROR_AUTHENTICATE == err || EMF_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
+ if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed : Login or Authentication fail 2 - %d", err);
- }
- else if (EMF_ERROR_CONNECTION_FAILURE != err) {
- err = EMF_ERROR_VALIDATE_ACCOUNT;
}
- account->sending_security = 0x01; /* restore to the previous value */
+ else if (EMAIL_ERROR_CONNECTION_FAILURE != err) {
+ err = EMAIL_ERROR_VALIDATE_ACCOUNT;
+ }
+ account->outgoing_server_secure_connection = 0x01; /* restore to the previous value */
goto FINISH_OFF;
}
if (!emcore_check_thread_status()) {
- err = EMF_ERROR_CANCELLED;
+ err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
- /* save sending_security = 0x02 (tls) to the d */
+ /* save outgoing_server_secure_connection = 0x02 (tls) to the d */
if (!emstorage_update_account(account_id, (emstorage_account_tbl_t *)account, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_update_account failed - %d", err);
- account->sending_security = 0x01; /* restore to the previous value */
- err = EMF_ERROR_VALIDATE_ACCOUNT;
+ account->outgoing_server_secure_connection = 0x01; /* restore to the previous value */
+ err = EMAIL_ERROR_VALIDATE_ACCOUNT;
goto FINISH_OFF;
}
}
else {
- if (EMF_ERROR_CONNECTION_FAILURE != err)
- err = EMF_ERROR_VALIDATE_ACCOUNT;
+ if (EMAIL_ERROR_CONNECTION_FAILURE != err)
+ err = EMAIL_ERROR_VALIDATE_ACCOUNT;
goto FINISH_OFF;
}
}
/* validate connection for pop3/ima */
EM_DEBUG_LOG("Validate connection for POP3/IMAP4");
- if (EMF_ERROR_NONE == err) {
+ if (EMAIL_ERROR_NONE == err) {
if (!emcore_check_thread_status()) {
- err = EMF_ERROR_CANCELLED;
- goto FINISH_OFF;
+ err = EMAIL_ERROR_CANCELLED;
+ goto FINISH_OFF;
}
-
- if (!emcore_connect_to_remote_mailbox_with_account_info(account, NULL, (void **)&tmp_stream, &err) || !tmp_stream)
+
+ if (!emcore_connect_to_remote_mailbox_with_account_info(account, 0, (void **)&tmp_stream, &err) || !tmp_stream)
{
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err);
- if (EMF_ERROR_AUTHENTICATE == err || EMF_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
+ if (EMAIL_ERROR_AUTHENTICATE == err || EMAIL_ERROR_LOGIN_FAILURE == err) { /* wrong password or etc */
EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed : Login or Authentication failed - %d", err);
}
- else if (EMF_ERROR_CONNECTION_FAILURE != err) {
- /* err = EMF_ERROR_VALIDATE_ACCOUNT */
+ else if (EMAIL_ERROR_CONNECTION_FAILURE != err) {
+ /* err = EMAIL_ERROR_VALIDATE_ACCOUNT */
}
goto FINISH_OFF;
- }
+ }
}
-
+
if (!emcore_check_thread_status()) {
- if (!emcore_delete_account_(account->account_id, NULL))
+ if (!emcore_delete_account(account->account_id, NULL))
EM_DEBUG_EXCEPTION("emdaemon_delete_account failed [%d]", account->account_id);
- err = EMF_ERROR_CANCELLED;
+ err = EMAIL_ERROR_CANCELLED;
goto FINISH_OFF;
}
-
+
ret = true;
-FINISH_OFF:
+FINISH_OFF:
if (stream)
smtp_close(stream);
-
+
if (tmp_stream)
emcore_close_mailbox(0 , tmp_stream);
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
- int err = EMF_ERROR_NONE, ret = false;
- emf_account_t *ref_account = NULL;
+ int err = EMAIL_ERROR_NONE, ret = false;
+ email_account_t *ref_account = NULL;
- if (account_id <= 0)
+ if (account_id <= 0)
{
EM_DEBUG_EXCEPTION("account_id[%p]", account_id);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
ret = true;
-FINISH_OFF:
+FINISH_OFF:
if (err_code)
*err_code = err;
return ret;
}
-INTERNAL_FUNC int emcore_delete_account_(int account_id, int *err_code)
+INTERNAL_FUNC int emcore_delete_account(int account_id, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_id[%d], err_code[%p]", account_id, err_code);
-
+
/* default variabl */
int ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
- if (account_id < FIRST_ACCOUNT_ID) {
+ if (account_id < FIRST_ACCOUNT_ID) {
EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
-#ifdef __FEATURE_LOCAL_ACTIVITY__
+#ifdef __FEATURE_LOCAL_ACTIVITY__
/* Delete all local activities of previous account */
emstorage_activity_tbl_t activity;
memset(&activity, 0x00, sizeof(emstorage_activity_tbl_t));
activity.account_id = account_id;
-
+
if (!emcore_delete_activity(&activity, &err)) {
EM_DEBUG_LOG("\t emcore_delete_activity failed - %d", err);
-
+
goto FINISH_OFF;
}
-#endif
+#endif
#ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__
if (false == emcore_clear_partial_body_thd_event_que(&err))
if (false == emstorage_delete_full_pbd_activity_data(account_id, true, &err))
EM_DEBUG_EXCEPTION("emstorage_delete_full_pbd_activity_data failed [%d]", err);
-
-#endif
-#ifdef __FEATURE_USING_MY_ACCOUNT__
- {
- int error_code;
- emf_account_t *account_to_be_deleted;
-
- account_to_be_deleted = emcore_get_account_reference(account_id);
- if (account_to_be_deleted && account_to_be_deleted->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
- EM_DEBUG_LOG("Calling account_svc_delete with my_account_id[%d]", account_to_be_deleted->my_account_id);
- error_code = account_connect();
- EM_DEBUG_LOG("account_connect returns [%d]", error_code);
- account_delete_from_db_by_id(account_to_be_deleted->my_account_id);
- error_code = account_disconnect();
- EM_DEBUG_LOG("account_disconnect returns [%d]", error_code);
- }
- }
#endif
- if (emcore_cancel_all_threads_of_an_account(account_id) < EMF_ERROR_NONE) {
+
+ if (emcore_cancel_all_threads_of_an_account(account_id) < EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("There are some remaining jobs. I couldn't stop them.");
- err = EMF_ERROR_CANNOT_STOP_THREAD;
+ err = EMAIL_ERROR_CANNOT_STOP_THREAD;
goto FINISH_OFF;
}
-
- emf_mailbox_t mbox;
/* BEGIN TRANSACTION; */
emstorage_begin_transaction(NULL, NULL, NULL);
if (!emstorage_delete_account(account_id, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_account failed - %d", err);
+ EM_DEBUG_EXCEPTION("emstorage_delete_account failed [%d]", err);
goto FINISH_OFF;
}
-
+
#ifdef __FEATURE_KEEP_CONNECTION__
/* emcore_reset_streams(); */
emcore_remove_connection_info(account_id);
#endif
- mbox.account_id = account_id;
- mbox.name = NULL;
-
- if (!emcore_delete_mail_all(&mbox, 0, &err)) {
- EM_DEBUG_EXCEPTION("emcore_delete_mail_all failed - %d", err);
+ if ((err = emcore_delete_all_mails_of_acount(account_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_delete_all_mails_of_acount failed [%d]", err);
goto FINISH_OFF;
}
-
+
/* delete all mailboxe */
- if (!emstorage_delete_mailbox(account_id, -1, NULL, false, &err)) {
+ if (!emstorage_delete_mailbox(account_id, -1, 0, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_delete_mailbox failed - %d", err);
goto FINISH_OFF;
}
-
+
/* delete local imap sync mailbox from imap mailbox tabl */
if (!emstorage_remove_downloaded_mail(account_id, NULL, NULL, false, &err)) {
EM_DEBUG_EXCEPTION("emstorage_remove_downloaded_mail failed - %d", err);
emcore_check_unread_mail();
emcore_delete_notification_by_account(account_id);
emcore_refresh_account_reference();
-
+
ret = true;
-
-FINISH_OFF:
+
+FINISH_OFF:
if (ret == true) { /* COMMIT TRANSACTION; */
if (emstorage_commit_transaction(NULL, NULL, NULL) == false) {
- err = EMF_ERROR_DB_FAILURE;
+ err = EMAIL_ERROR_DB_FAILURE;
ret = false;
}
if (!emstorage_notify_storage_event(NOTI_ACCOUNT_DELETE, account_id, 0, NULL, 0))
}
else { /* ROLLBACK TRANSACTION; */
if (emstorage_rollback_transaction(NULL, NULL, NULL) == false)
- err = EMF_ERROR_DB_FAILURE;
+ err = EMAIL_ERROR_DB_FAILURE;
if (!emstorage_notify_storage_event(NOTI_ACCOUNT_DELETE_FAIL, account_id, err, NULL, 0))
EM_DEBUG_EXCEPTION(" emstorage_notify_storage_event[ NOTI_ACCOUNT_DELETE] : Notification Failed >>> ");
- }
+ }
if (err_code)
*err_code = err;
return ret;
}
-INTERNAL_FUNC int emcore_create_account(emf_account_t *account, int *err_code)
+INTERNAL_FUNC int emcore_create_account(email_account_t *account, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account[%p], err_code[%p]", account, err_code);
-
+
int ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
int i, count = 0, is_preset_IMAP_account = false;
- emf_mailbox_t local_mailbox = {0};
+ email_mailbox_t local_mailbox = {0};
emstorage_account_tbl_t *temp_account_tbl = NULL;
-
+
if (!account) {
EM_DEBUG_EXCEPTION("account[%p]", account);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
-
+
if (!emstorage_get_account_count(&count, true, &err)) {
EM_DEBUG_EXCEPTION("emstorage_get_account_count failed - %d", err);
goto FINISH_OFF;
}
- if (count >= EMF_ACCOUNT_MAX) {
+ if (count >= EMAIL_ACCOUNT_MAX) {
EM_DEBUG_EXCEPTION("too many accounts...");
- err = EMF_ERROR_ACCOUNT_MAX_COUNT;
+ err = EMAIL_ERROR_ACCOUNT_MAX_COUNT;
goto FINISH_OFF;
}
account->account_id = 0;
- /* check for email address validation */
- EM_DEBUG_LOG("account->email_addr[%s]", account->email_addr);
- if (account->email_addr) {
- if (!em_verify_email_address(account->email_addr, true, &err)) {
- err = EMF_ERROR_INVALID_ADDRESS;
- EM_DEBUG_EXCEPTION("Invalid Email Address");
- goto FINISH_OFF;
- }
+ /* Temporarily code - begin */
+ if (account->auto_download_size == 0) {
+ account->auto_download_size = PARTIAL_BODY_SIZE_IN_BYTES;
+ EM_DEBUG_LOG("account->auto_download_size [%d]", account->auto_download_size);
}
-#ifdef __FEATURE_USING_MY_ACCOUNT__
- if (account->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
- int account_svc_id = 0;
- int error_code;
- account_h account_handle = NULL;
-
- error_code = account_connect();
- error_code = account_create(&account_handle);
-
- if(error_code != ACCOUNT_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("account_create failed [%d]", error_code);
- err = error_code;
- goto FINISH_OFF;
- }
+ if (account->default_mail_slot_size == 0) {
+ account->default_mail_slot_size = 50;
+ EM_DEBUG_LOG("account->default_mail_slot_size [%d]", account->default_mail_slot_size);
+ }
+ /* Temporarily code - end */
- account_set_user_name(account_handle, account->user_name);
- account_set_domain_name(account_handle, account->account_name);
- account_set_email_address(account_handle, account->email_addr);
- account_set_source(account_handle, "SLP EMAIL");
- account_set_package_name(account_handle, "email-setting-efl");
- account_set_capability(account_handle , ACCOUNT_CAPABILITY_EMAIL, ACCOUNT_CAPABILITY_ENABLED);
- if (account->logo_icon_path)
- account_set_icon_path(account_handle, account->logo_icon_path);
- error_code = account_insert_to_db(account_handle, &account_svc_id);
-
- if (error_code != ACCOUNT_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("account_insert_to_db failed [%d]", error_code);
- err = error_code;
+ /* check for email address validation */
+ EM_DEBUG_LOG("account->user_email_address[%s]", account->user_email_address);
+ if (account->user_email_address) {
+ if (!em_verify_email_address(account->user_email_address, true, &err)) {
+ err = EMAIL_ERROR_INVALID_ADDRESS;
+ EM_DEBUG_EXCEPTION("Invalid Email Address");
goto FINISH_OFF;
}
-
- account->my_account_id = account_svc_id;
-
- EM_DEBUG_LOG("account_insert_to_db succeed");
-
- account_disconnect();
}
-#endif /* __FEATURE_USING_MY_ACCOUNT__ */
temp_account_tbl = em_malloc(sizeof(emstorage_account_tbl_t));
if (!temp_account_tbl) {
goto FINISH_OFF;
}
account->account_id = temp_account_tbl->account_id;
- is_preset_IMAP_account = ((account->receiving_server_type == EMF_SERVER_TYPE_IMAP4)) ? true : false;/* && (account->preset_account)) ? true : false */
+ is_preset_IMAP_account = ((account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4)) ? true : false;/* && (account->is_preset_account)) ? true : false */
EM_DEBUG_LOG("is_preset_IMAP_account : %d", is_preset_IMAP_account);
- if ((account->receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) && (!is_preset_IMAP_account)) {
+ if ((account->incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) && (!is_preset_IMAP_account)) {
/* 1. create default local mailbox
* (Inbox, Draft, Outbox, Sentbox) */
for (i = 0; i < MAILBOX_COUNT; i++) {
EM_DEBUG_LOG("g_default_mbox_name [%d/%d] is [%s]", i, MAILBOX_COUNT, g_default_mbox_name[i]);
local_mailbox.account_id = temp_account_tbl->account_id;
- local_mailbox.name = g_default_mbox_name[i];
+ local_mailbox.mailbox_name = g_default_mbox_name[i];
local_mailbox.mailbox_type = g_default_mbox_type[i];
- if (local_mailbox.mailbox_type == EMF_MAILBOX_TYPE_INBOX) {
- local_mailbox.local = EMF_MAILBOX_FROM_SERVER;
- local_mailbox.synchronous = 1;
+ if (local_mailbox.mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) {
+ local_mailbox.local = EMAIL_MAILBOX_FROM_SERVER;
}
else {
- local_mailbox.local = EMF_MAILBOX_FROM_LOCAL;
- local_mailbox.synchronous = 0;
+ local_mailbox.local = EMAIL_MAILBOX_FROM_LOCAL;
}
local_mailbox.alias = g_default_mbox_alias[i];
emcore_get_default_mail_slot_count(&local_mailbox.mail_slot_size, NULL);
emstorage_free_account(&temp_account_tbl, 1, NULL);
if (ret == false && account != NULL) {
- if (!emcore_delete_account_(account->account_id, NULL))
+ if (!emcore_delete_account(account->account_id, NULL))
EM_DEBUG_EXCEPTION("emdaemon_delete_account Failed [%d]", account->account_id);
}
{
EM_DEBUG_FUNC_BEGIN();
- int ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
- emf_account_list_t *account_list = NULL;
- emf_account_list_t **p = NULL;
- emf_account_t *account = NULL;
+ email_account_list_t *account_list = NULL;
+ email_account_list_t **p = NULL;
+ email_account_t *account = NULL;
emstorage_account_tbl_t *account_tbl_array = NULL;
int count = 0;
int i = 0;
if (!g_account_retrieved) {
count = 1000;
if (!emstorage_get_account_list(&count, &account_tbl_array, true, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_account_list failed - %d", err);
+ EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
goto FINISH_OFF;
}
for (p = &account_list, i = 0; i < count; i++) {
- account = malloc(sizeof(emf_account_t));
+ account = em_malloc(sizeof(email_account_t));
if (!account) {
EM_DEBUG_EXCEPTION("malloc failed...");
- err = EMF_ERROR_OUT_OF_MEMORY;
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
em_convert_account_tbl_to_account(account_tbl_array + i, account);
- /* memcpy(account, accounts + i, sizeof(emf_account_t)) */
- /* memset(accounts + i, 0x00, sizeof(emf_account_t)) */
+ /* memcpy(account, accounts + i, sizeof(email_account_t)) */
+ /* memset(accounts + i, 0x00, sizeof(email_account_t)) */
- (*p) = malloc(sizeof(emf_account_list_t));
+ *p = (email_account_list_t*) em_malloc(sizeof(email_account_list_t));
if (!(*p)) {
EM_DEBUG_EXCEPTION("malloc failed...");
- err = EMF_ERROR_OUT_OF_MEMORY;
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
- memset((*p), 0x00, sizeof(emf_account_list_t));
(*p)->account = account;
g_account_list = account_list;
}
- ret = true;
-
FINISH_OFF:
- if (account_tbl_array != NULL)
+ if (account_tbl_array)
emstorage_free_account(&account_tbl_array, count, NULL);
- if (!ret) {
+ if (err != EMAIL_ERROR_NONE) {
g_account_list = account_list;
emcore_free_account_reference();
}
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
}
INTERNAL_FUNC int emcore_refresh_account_reference()
g_account_num = 0;
g_account_list = NULL;
- if (!emcore_init_account_reference()) {
+ if (emcore_init_account_reference() != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_init_account_reference failed...");
return false;
}
{
EM_DEBUG_FUNC_BEGIN();
- emf_account_list_t *p = g_account_list, *p_next;
+ email_account_list_t *p = g_account_list;
+ email_account_list_t *p_next = NULL;
while (p) {
- emcore_free_account(&p->account, 1, NULL);
+ emcore_free_account(p->account);
+ EM_SAFE_FREE(p->account);
p_next = p->next;
- free(p);
+ EM_SAFE_FREE(p);
p = p_next;
}
return true;
}
-INTERNAL_FUNC int emcore_free_account(emf_account_t **account_list, int count, int *err_code)
+INTERNAL_FUNC int emcore_free_account_list(email_account_t **account_list, int count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d], err_code[%p]", account_list, count, err_code);
- /* default variabl */
int ret = false;
- int err = EMF_ERROR_NONE;
+ int err = EMAIL_ERROR_NONE;
- if (count > 0) {
- if (!account_list || !*account_list) {
- err = EMF_ERROR_INVALID_PARAM;
+ if (count <= 0 || !account_list || !*account_list) {
+ err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
- }
-
- emf_account_t *p = *account_list;
- int i;
+ }
- for (i = 0; i < count; i++) {
- EM_SAFE_FREE(p[i].account_name);
- EM_SAFE_FREE(p[i].receiving_server_addr);
- EM_SAFE_FREE(p[i].email_addr);
- EM_SAFE_FREE(p[i].user_name);
- EM_SAFE_FREE(p[i].password);
- EM_SAFE_FREE(p[i].sending_server_addr);
- EM_SAFE_FREE(p[i].sending_user);
- EM_SAFE_FREE(p[i].sending_password);
- EM_SAFE_FREE(p[i].display_name);
- EM_SAFE_FREE(p[i].reply_to_addr);
- EM_SAFE_FREE(p[i].return_addr);
- EM_SAFE_FREE(p[i].logo_icon_path);
- EM_SAFE_FREE(p[i].options.display_name_from);
- EM_SAFE_FREE(p[i].options.signature);
- }
+ email_account_t *p = *account_list;
+ int i;
+ for (i = 0; i < count; i++)
+ emcore_free_account(p+i);
- EM_SAFE_FREE(p); *account_list = NULL;
- }
+ EM_SAFE_FREE(p);
+ *account_list = NULL;
ret = true;
return ret;
}
+INTERNAL_FUNC void emcore_free_option(email_option_t *option)
+{
+ EM_SAFE_FREE(option->display_name_from);
+ EM_SAFE_FREE(option->signature);
+}
-INTERNAL_FUNC int emcore_get_account_reference_list(emf_account_t **account_list, int *count, int *err_code)
+
+INTERNAL_FUNC void emcore_free_account(email_account_t *account)
+{
+ if(!account) return;
+
+ EM_SAFE_FREE(account->account_name);
+ EM_SAFE_FREE(account->incoming_server_address);
+ EM_SAFE_FREE(account->user_email_address);
+ EM_SAFE_FREE(account->incoming_server_user_name);
+ EM_SAFE_FREE(account->incoming_server_password);
+ EM_SAFE_FREE(account->outgoing_server_address);
+ EM_SAFE_FREE(account->outgoing_server_user_name);
+ EM_SAFE_FREE(account->outgoing_server_password);
+ EM_SAFE_FREE(account->user_display_name);
+ EM_SAFE_FREE(account->reply_to_address);
+ EM_SAFE_FREE(account->return_address);
+ EM_SAFE_FREE(account->logo_icon_path);
+ EM_SAFE_FREE(account->certificate_path);
+ EM_SAFE_FREE(account->user_data);
+ account->user_data_length = 0;
+ emcore_free_option(&account->options);
+
+
+ EM_DEBUG_FUNC_END();
+}
+
+
+INTERNAL_FUNC int emcore_get_account_reference_list(email_account_t **account_list, int *count, int *err_code)
{
EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%p], err_code[%p]", account_list, count, err_code);
int i, countOfAccounts = 0;
int ret = false;
- int err = EMF_ERROR_NONE;
- emf_account_t *accountRef;
- emf_account_list_t *p;
+ int err = EMAIL_ERROR_NONE;
+ email_account_t *accountRef;
+ email_account_list_t *p;
if (!account_list || !count) {
EM_DEBUG_EXCEPTION("account_list[%p], count[%p]", account_list, count);
- err = EMF_ERROR_INVALID_PARAM;
+ err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
*count = countOfAccounts;
if (countOfAccounts > 0) {
- *account_list = malloc(sizeof(emf_account_t) * countOfAccounts);
+ *account_list = malloc(sizeof(email_account_t) * countOfAccounts);
if (!*account_list) {
EM_DEBUG_LOG("malloc failed...");
- err = EMF_ERROR_OUT_OF_MEMORY;
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
}
p = g_account_list;
for (i = 0; i < countOfAccounts; i++) {
accountRef = (*account_list) + i;
- memcpy(accountRef, p->account , sizeof(emf_account_t));
+ memcpy(accountRef, p->account , sizeof(email_account_t));
p = p->next;
}
static int append_data_into_buffer(char **target_buffer, int *target_buffer_lenth, char *input_data, int input_data_length, int *error_code)
{
EM_DEBUG_FUNC_BEGIN("target_buffer [%p], target_buffer_lenth [%p], input_data [%p], input_data_length[%d]", target_buffer, target_buffer_lenth, input_data, input_data_length);
- int local_error_code = EMF_ERROR_NONE, ret_code = false;
+ int local_error_code = EMAIL_ERROR_NONE, ret_code = false;
if (!target_buffer || !target_buffer_lenth || !input_data) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- local_error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ local_error_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
*target_buffer = realloc(*target_buffer, (*target_buffer_lenth) + input_data_length);
if (!*target_buffer) {
EM_DEBUG_EXCEPTION("realloc failed");
- local_error_code = EMF_ERROR_OUT_OF_MEMORY;
+ local_error_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
memcpy(*target_buffer + (*target_buffer_lenth), input_data, input_data_length);
EM_DEBUG_LOG("*target_buffer_lenth [%d] input_data_length [%d]", *target_buffer_lenth, input_data_length);
}
else {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- local_error_code = EMF_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
+ local_error_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
static int emcore_write_account_into_buffer(char **target_buffer, int *target_buffer_lenth, emstorage_account_tbl_t *account_tbl_ptr, int *error_code)
{
EM_DEBUG_FUNC_BEGIN("target_buffer [%p], target_buffer_lenth [%p], account_tbl_ptr [%p], error_code [%p]", target_buffer, target_buffer_lenth, account_tbl_ptr, error_code);
- int local_error_code = EMF_ERROR_NONE, ret_code = false, stream_length = 0;
- emf_account_t *temp_account = NULL;
+ int local_error_code = EMAIL_ERROR_NONE, ret_code = false, stream_length = 0;
+ email_account_t temp_account = {0};
char *byte_stream = NULL;
- temp_account = em_malloc(sizeof(emf_account_t));
- memset(temp_account, 0, sizeof(emf_account_t));
-
- if (em_convert_account_tbl_to_account(account_tbl_ptr, temp_account)) {
- byte_stream = em_convert_account_to_byte_stream(temp_account, &stream_length);
+ if (em_convert_account_tbl_to_account(account_tbl_ptr, &temp_account)) {
+ byte_stream = em_convert_account_to_byte_stream(&temp_account, &stream_length);
EM_DEBUG_LOG("stream_length [%d]", stream_length);
- /* EM_DEBUG_LOG("password [%s]", temp_account->password) */
+ /* EM_DEBUG_LOG("incoming_server_password [%s]", temp_account->password) */
if (byte_stream) {
if (!append_data_into_buffer(target_buffer, target_buffer_lenth, (char *)&stream_length, sizeof(int), &local_error_code)) {
}
else {
EM_DEBUG_EXCEPTION("em_convert_account_tbl_to_account failed");
- local_error_code = EMF_ERROR_SYSTEM_FAILURE;
+ local_error_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
ret_code = true;
FINISH_OFF:
- if (temp_account)
- emcore_free_account(&temp_account, 1, NULL);
+ emcore_free_account(&temp_account);
if (error_code)
*error_code = local_error_code;
INTERNAL_FUNC int emcore_backup_accounts(const char *file_path, int *error_code)
{
EM_DEBUG_FUNC_BEGIN("file_path [%s], error_code [%p]", file_path, error_code);
- int local_error_code = EMF_ERROR_NONE, local_error_code_2 = EMF_ERROR_NONE, ret_code = false;
+ int local_error_code = EMAIL_ERROR_NONE, local_error_code_2 = EMAIL_ERROR_NONE, ret_code = false;
int select_num, i, target_buff_length = 0;
char *target_buffer = NULL;
emstorage_account_tbl_t *account_list = NULL;
if (!file_path) {
- local_error_code = EMF_ERROR_INVALID_PARAM;
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ local_error_code = EMAIL_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
goto FINISH_OFF;
}
EM_DEBUG_LOG("select_num [%d]", select_num);
if (account_list) {
- target_buffer = malloc(sizeof(int));
+ target_buffer = em_malloc(sizeof(int));
if (!target_buffer) {
EM_DEBUG_EXCEPTION("malloc failed");
- local_error_code = EMF_ERROR_OUT_OF_MEMORY;
+ local_error_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
if (ssm_write_buffer(target_buffer, target_buff_length, file_path, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
EM_DEBUG_EXCEPTION("ssm_write_buffer failed [%d]", local_error_code);
- local_error_code = EMF_ERROR_SYSTEM_FAILURE;
+ local_error_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
INTERNAL_FUNC int emcore_restore_accounts(const char *file_path, int *error_code)
{
EM_DEBUG_FUNC_BEGIN("file_path [%s], error_code [%p]", file_path, error_code);
- int local_error_code = EMF_ERROR_NONE, ret_code = false, buffer_length = 0, read_length = 0;
+ int local_error_code = EMAIL_ERROR_NONE, ret_code = false, buffer_length = 0, read_length = 0;
int account_count = 0, i = 0, account_stream_length = 0;
char *temp_buffer = NULL, *account_stream = NULL, *buffer_ptr = NULL;
- emf_account_t *temp_account = NULL, *account_list = NULL;
+ email_account_t temp_account = {0};
+ email_account_t *account_list = NULL;
ssm_file_info_t sfi;
if (!file_path) {
- local_error_code = EMF_ERROR_INVALID_PARAM;
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
+ local_error_code = EMAIL_ERROR_INVALID_PARAM;
+ EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
goto FINISH_OFF;
}
if (emcore_get_account_reference_list(&account_list, &account_count, &ret_code)) {
for (i = 0; i < account_count; i++) {
- if (account_list[i].receiving_server_type != EMF_SERVER_TYPE_ACTIVE_SYNC) {
- if (!emcore_delete_account_(account_list[i].account_id, &ret_code)) {
- local_error_code = EMF_ERROR_INVALID_ACCOUNT;
- EM_DEBUG_EXCEPTION("emcore_delete_account_ failed");
+ if (account_list[i].incoming_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
+ if (!emcore_delete_account(account_list[i].account_id, &ret_code)) {
+ local_error_code = EMAIL_ERROR_INVALID_ACCOUNT;
+ EM_DEBUG_EXCEPTION("emcore_delete_account failed");
goto FINISH_OFF;
}
}
if (ssm_getinfo(file_path, &sfi, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
EM_DEBUG_EXCEPTION("ssm_getinfo() failed.");
- ret_code = EMF_ERROR_SYSTEM_FAILURE;
+ ret_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
EM_DEBUG_LOG("account buffer_length[%d]", buffer_length);
if ((temp_buffer = (char *)em_malloc(buffer_length + 1)) == NULL) {
EM_DEBUG_EXCEPTION("em_malloc failed...");
- ret_code = EMF_ERROR_OUT_OF_MEMORY;
+ ret_code = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
if (ssm_read(file_path, temp_buffer, buffer_length, (size_t *)&read_length, SSM_FLAG_SECRET_OPERATION, NULL) < 0) {
EM_DEBUG_EXCEPTION("ssm_read() failed.");
- ret_code = EMF_ERROR_SYSTEM_FAILURE;
+ ret_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
account_stream = em_malloc(account_stream_length);
if (!account_stream) {
EM_DEBUG_EXCEPTION("em_malloc() failed.");
- ret_code = EMF_ERROR_OUT_OF_MEMORY ;
+ ret_code = EMAIL_ERROR_OUT_OF_MEMORY ;
goto FINISH_OFF;
}
memcpy(account_stream, buffer_ptr, account_stream_length);
- temp_account = em_malloc(sizeof(emf_account_t));
-
- if (!temp_account) {
- EM_DEBUG_EXCEPTION("em_malloc() failed.");
- ret_code = EMF_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- em_convert_byte_stream_to_account(account_stream, temp_account);
+ em_convert_byte_stream_to_account(account_stream, account_stream_length, &temp_account);
EM_SAFE_FREE(account_stream);
- if (!emcore_create_account(temp_account, &ret_code)) {
+ if (!emcore_create_account(&temp_account, &ret_code)) {
EM_DEBUG_EXCEPTION("emcore_create_account() failed.");
goto FINISH_OFF;
}
- emcore_free_account(&temp_account, 1, &ret_code);
- temp_account = NULL;
+ emcore_free_account(&temp_account);
}
buffer_ptr += account_stream_length;
account_stream_length = 0;
}
} else {
EM_DEBUG_EXCEPTION("ssm_read() failed.");
- ret_code = EMF_ERROR_SYSTEM_FAILURE;
+ ret_code = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
ret_code = true;
FINISH_OFF:
- if (temp_account)
- emcore_free_account(&temp_account, 1, NULL);
+ emcore_free_account(&temp_account);
EM_SAFE_FREE(account_stream);
EM_SAFE_FREE(temp_buffer);
#endif /* __FEATURE_BACKUP_ACCOUNT_ */
-#ifdef __FEATURE_WDS_SUPPORT__
-#include <curl/curl.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-static int emcore_fetch_server_info_from_wds(const char *domain_name, char **output_file_path)
+INTERNAL_FUNC int emcore_query_server_info(const char* domain_name, email_server_info_t **result_server_info)
{
- EM_DEBUG_FUNC_BEGIN("domain_name [%s]", domain_name);
- CURL *curl = NULL;
- int ret_code = EMF_ERROR_NONE, curl_error = CURLE_OK, file_path_len = 0;
- char *wds_url = "https://servicemine-api.wdsglobal.com/servicemine-api/email?domainName=";
- char *query_url = NULL;
- char *user_password = "samsung:xi7Claso";
- char curl_error_buffer[CURL_ERROR_SIZE] = { 0, };
- FILE *file_from_curl = NULL;
-
- if(!domain_name) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- ret_code = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- query_url = em_malloc(strlen(wds_url) + strlen(domain_name) + 1);
-
- if(!query_url) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
- ret_code = EMF_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
+ EM_DEBUG_FUNC_BEGIN("domain_name [%s], result_server_info [%p]", domain_name, result_server_info);
+ int ret_code = EMAIL_ERROR_NONE;
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
- sprintf(query_url, "%s%s", wds_url, domain_name);
-
- curl = curl_easy_init();
- if(!curl) {
- EM_DEBUG_EXCEPTION("curl_easy_init failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
+INTERNAL_FUNC int emcore_free_server_info(email_server_info_t **target_server_info)
+{
+ EM_DEBUG_FUNC_BEGIN("result_server_info [%p]", target_server_info);
+ int i, ret_code = EMAIL_ERROR_NONE;
+ email_server_info_t *server_info = NULL;
- if( (curl_error = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_ERRORBUFFER failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
+ if(target_server_info && *target_server_info) {
+ server_info = *target_server_info;
+ EM_SAFE_FREE(server_info->service_name);
+ for(i = 0; i < server_info->protocol_conf_count; i++) {
+ EM_SAFE_FREE(server_info->protocol_config_array[i].server_addr);
+ }
+ EM_SAFE_FREE(server_info->protocol_config_array);
+ EM_SAFE_FREE(server_info);
}
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
- if( (curl_error = curl_easy_setopt(curl, CURLOPT_URL, query_url) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_URL failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
+INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%d]", input_account_id);
+ int ret_code = EMAIL_ERROR_NONE, result_value = 0;
- if( (curl_error = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_HTTPAUTH failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
+ result_value = vconf_set_int(VCONF_KEY_DEFAULT_ACCOUNT_ID, input_account_id);
+ if (result_value < 0) {
+ EM_DEBUG_EXCEPTION("vconf_set_int failed [%d]", result_value);
+ ret_code = EMAIL_ERROR_SYSTEM_FAILURE;
}
- if( (curl_error = curl_easy_setopt(curl, CURLOPT_USERPWD, user_password) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_USERPWD failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
+ EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
+ return ret_code;
+}
- if( (curl_error = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_HTTPGET failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
+static int _recover_from_invalid_default_account_id(int *output_account_id)
+{
+ EM_DEBUG_FUNC_BEGIN("account_id [%p]", output_account_id);
+ int ret_code = EMAIL_ERROR_NONE;
+ int account_count = 100;
+ emstorage_account_tbl_t *result_account_list = NULL;
- if( (curl_error = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_SSL_VERIFYPEER failed");
- ret_code = EMF_ERROR_UNKNOWN;
+ if (output_account_id == NULL) {
+ ret_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- file_path_len = strlen(MAILHOME "/tmp/") + strlen(domain_name) + strlen(".xml") + 1;
- *output_file_path = em_malloc(file_path_len + 1);
-
- if(!output_file_path) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_OUT_OF_MEMORY");
- ret_code = EMF_ERROR_OUT_OF_MEMORY;
+ if(!emstorage_get_account_list(&account_count, &result_account_list, false, false, &ret_code) || !result_account_list) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_list() failed [%d]", ret_code);
+ *output_account_id = 0;
goto FINISH_OFF;
}
- snprintf(*output_file_path, file_path_len, "%s%s%s", "/tmp/", domain_name, ".xml");
-
- file_from_curl = fopen(*output_file_path, "w");
-
- if(!file_from_curl) {
- EM_DEBUG_EXCEPTION("fopen failed [%s]", *output_file_path);
- ret_code = EMF_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- if( (curl_easy_setopt(curl, CURLOPT_WRITEDATA, file_from_curl) ) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_setopt for CURLOPT_WRITEDATA failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- if(curl_easy_perform(curl) != CURLE_OK) {
- EM_DEBUG_EXCEPTION("curl_easy_perform failed [%s]", curl_error_buffer);
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
+ if (account_count > 0) {
+ *output_account_id = result_account_list[0].account_id;
}
- EM_DEBUG_LOG("curl_easy_perform passed");
-
-FINISH_OFF:
- if(file_from_curl)
- fclose(file_from_curl);
+ EM_DEBUG_LOG("output_account_id [%d]", *output_account_id);
- EM_SAFE_FREE(query_url);
+FINISH_OFF:
- if(curl)
- curl_easy_cleanup(curl);
+ if (result_account_list)
+ emstorage_free_account(&result_account_list, account_count, NULL);
EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
return ret_code;
}
-static int emcore_parse_server_info_from_wds(char *xml_file_path, emf_server_info_t **result_server_info)
+INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id)
{
- EM_DEBUG_FUNC_BEGIN("xml_file_path [%s], result_server_info [%p]", xml_file_path, result_server_info);
-
- int ret_code = EMF_ERROR_NONE;
- xmlDocPtr doc = NULL;
- xmlXPathContextPtr xpath_context = NULL;
- xmlXPathObjectPtr xpath_obj_service = NULL, xpath_obj_configuration = NULL, xpath_obj_result_of_query = NULL;
- xmlChar *xpath_service = (xmlChar*)"/servicemine/discovery/*/service-provider/service";
- xmlChar *xpath_configuration = (xmlChar*)"/servicemine/discovery/*/service-provider/service/configuration";
- xmlChar *xpath_configuration_query = NULL;
- xmlChar *service_name = NULL, *id_string = NULL, *result_content = NULL;
- emf_server_info_t *server_info = NULL;
- int i, j, id_len;
-
- if(!xml_file_path || !result_server_info) {
- EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
- ret_code = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
+ EM_DEBUG_FUNC_BEGIN("account_id [%p]", output_account_id);
+ int ret_code = EMAIL_ERROR_NONE;
+ int result_value = 0;
+ emstorage_account_tbl_t *result_account = NULL;
- xmlInitParser();
- LIBXML_TEST_VERSION;
-
- doc = xmlReadFile(xml_file_path, NULL, 0);
- if (doc == NULL) {
- EM_DEBUG_EXCEPTION("Failed to parse [%s]", xml_file_path);
- ret_code = EMF_ERROR_UNKNOWN;
+ if (output_account_id == NULL) {
+ ret_code = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
- /* Create xpath evaluation context */
- xpath_context = xmlXPathNewContext(doc);
- if(xpath_context == NULL) {
- EM_DEBUG_EXCEPTION("unable to create new XPath context");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- xpath_obj_service = xmlXPathEvalExpression(xpath_service, xpath_context);
- if(xpath_obj_service == NULL) {
- EM_DEBUG_EXCEPTION("unable to evaluate xpath expression [%s]", xpath_service);
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
+ result_value = vconf_get_int(VCONF_KEY_DEFAULT_ACCOUNT_ID, output_account_id);
- if(xpath_obj_service->nodesetval->nodeNr > 0 && xpath_obj_service->nodesetval->nodeTab) {
- service_name = xmlGetProp(xpath_obj_service->nodesetval->nodeTab[0] , (xmlChar*)"name");
- if(service_name) {
- EM_DEBUG_LOG("service_name [%s]", service_name);
- }
- else {
- EM_DEBUG_EXCEPTION("xmlGetProp failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
- }
- else {
- EM_DEBUG_EXCEPTION("nodesetval empty");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- xpath_obj_configuration = xmlXPathEvalExpression(xpath_configuration, xpath_context);
- if(xpath_obj_configuration == NULL) {
- EM_DEBUG_EXCEPTION("unable to evaluate xpath expression [%s]", xpath_configuration);
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
+ if (result_value < 0) {
+ EM_DEBUG_EXCEPTION("vconf_get_int() failed [%d]", result_value);
+ ret_code = EMAIL_ERROR_SYSTEM_FAILURE;
+ *output_account_id = 0;
}
- server_info = em_malloc(sizeof(emf_server_info_t));
-
- if(!server_info){
- EM_DEBUG_EXCEPTION("em_malloc failed");
- ret_code = EMF_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
+ if (*output_account_id != 0) {
+ if (!emstorage_get_account_by_id(*output_account_id, EMAIL_ACC_GET_OPT_DEFAULT, &result_account, false, &ret_code)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_by_id() failed [%d]", ret_code);
+ if(ret_code == EMAIL_ERROR_ACCOUNT_NOT_FOUND)
+ *output_account_id = 0;
+ else
+ goto FINISH_OFF;
+ }
}
- server_info->service_name = (char*)service_name;
-
- if(xpath_obj_configuration->nodesetval->nodeNr) {
- EM_DEBUG_LOG("node count [%d]", xpath_obj_configuration->nodesetval->nodeNr);
- server_info->protocol_config_array = em_malloc(sizeof(emf_protocol_config_t) * xpath_obj_configuration->nodesetval->nodeNr);
- server_info->protocol_conf_count = xpath_obj_configuration->nodesetval->nodeNr;
- }
- else {
- EM_DEBUG_EXCEPTION("xmlXPathEvalExpression failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- for(i = 0; i < xpath_obj_configuration->nodesetval->nodeNr; i++) {
- id_string = xmlGetProp(xpath_obj_configuration->nodesetval->nodeTab[i] , (xmlChar*)"id");
- if(id_string) {
- EM_DEBUG_LOG("id_string [%s]", id_string);
- server_info->protocol_config_array[i].configuration_id = atoi((char*)id_string);
- id_len = strlen((char*)id_string);
- }
- else {
- EM_DEBUG_EXCEPTION("xmlGetProp failed");
- continue;
- }
-
- xpath_configuration_query = em_malloc(strlen((char*)xpath_configuration) + id_len + 300);
- if(!xpath_configuration_query) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
+ if (*output_account_id == 0) {
+ if ( (ret_code = _recover_from_invalid_default_account_id(output_account_id)) != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("_recover_from_invalid_default_account() failed [%d]", ret_code);
+ *output_account_id = 0;
}
-
- /* searching in discovery element */
-
- sprintf((char*)xpath_configuration_query, "/servicemine/discovery//service-provider/service/configuration[@id=\"%s\"]/email/*", (char*)id_string);
- EM_DEBUG_LOG("[%s]", xpath_configuration_query);
-
- xpath_obj_result_of_query = xmlXPathEvalExpression(xpath_configuration_query, xpath_context);
- if(xpath_obj_result_of_query == NULL) {
- EM_DEBUG_EXCEPTION("unable to evaluate xpath expression [%s]", xpath_configuration_query);
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- if(xpath_obj_result_of_query->nodesetval && xpath_obj_result_of_query->nodesetval->nodeNr) {
- EM_DEBUG_LOG("node count [%d]", xpath_obj_result_of_query->nodesetval->nodeNr);
- }
- else {
- EM_DEBUG_EXCEPTION("xmlXPathEvalExpression failed [%p]", xpath_obj_result_of_query->nodesetval);
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- for(j = 0; j < xpath_obj_result_of_query->nodesetval->nodeNr; j++) {
- if(xpath_obj_result_of_query->nodesetval->nodeTab[j]->name) {
- EM_DEBUG_LOG("element name [%s]", xpath_obj_result_of_query->nodesetval->nodeTab[j]->name);
- EM_DEBUG_LOG("element type [%d]", xpath_obj_result_of_query->nodesetval->nodeTab[j]->type);
- result_content = xmlNodeGetContent(xpath_obj_result_of_query->nodesetval->nodeTab[j]);
- EM_DEBUG_LOG("content name [%s]", (char*)result_content);
- if(strncmp((char*)xpath_obj_result_of_query->nodesetval->nodeTab[j]->name, "protocol", strlen("protocol")) == 0) {
- server_info->protocol_config_array[i].protocol_type = EMF_SERVER_TYPE_NONE;
- if(result_content) {
- if(strncmp((char*)result_content, "smtp", strlen("smtp")) == 0) {
- server_info->protocol_config_array[i].protocol_type = EMF_SERVER_TYPE_SMTP;
- }
- else if(strncmp((char*)result_content, "pop3", strlen("pop3")) == 0) {
- server_info->protocol_config_array[i].protocol_type = EMF_SERVER_TYPE_POP3;
- }
- else if(strncmp((char*)result_content, "imap4", strlen("imap4")) == 0) {
- server_info->protocol_config_array[i].protocol_type = EMF_SERVER_TYPE_IMAP4;
- }
- }
- EM_DEBUG_LOG("protocol_type [%d]", server_info->protocol_config_array[i].protocol_type);
- }
- else if(strncmp((char*)xpath_obj_result_of_query->nodesetval->nodeTab[j]->name, "encryption-type", strlen("encryption-type")) == 0) {
- server_info->protocol_config_array[i].security_type = 0;
- if(result_content) {
- if(strncmp((char*)result_content, "ssl/tls", strlen("ssl/tls")) == 0) {
- server_info->protocol_config_array[i].security_type = 1;
- }
- else if(strncmp((char*)result_content, "none", strlen("none")) == 0) {
- server_info->protocol_config_array[i].security_type = 0;
- }
-
- }
- EM_DEBUG_LOG("security_type [%d]", server_info->protocol_config_array[i].security_type);
- }
- else if(strncmp((char*)xpath_obj_result_of_query->nodesetval->nodeTab[j]->name, "requires-auth", strlen("requires-auth")) == 0) {
- if(result_content) {
- if(strncmp((char*)result_content, "true", strlen("true")) == 0) {
- server_info->protocol_config_array[i].auth_type = 1;
- }
- else {
- server_info->protocol_config_array[i].auth_type = 0;
- }
- }
- EM_DEBUG_LOG("auth_type [%d]", server_info->protocol_config_array[i].auth_type);
- }
- EM_SAFE_FREE(result_content);
- }
- }
-
- if(xpath_obj_result_of_query) {
- xmlXPathFreeObject(xpath_obj_result_of_query);
- xpath_obj_result_of_query = NULL;
- }
-
- /* searching server address in configuration-parameters element */
-
- sprintf((char*)xpath_configuration_query, "/servicemine/configuration-parameters/configuration[@id=\"%s\"]/wap-provisioningdoc/characteristic/characteristic[@type=\"APPADDR\"]/parm", (char*)id_string);
- EM_DEBUG_LOG("[%s]", xpath_configuration_query);
-
- xpath_obj_result_of_query = xmlXPathEvalExpression(xpath_configuration_query, xpath_context);
- if(xpath_obj_result_of_query == NULL) {
- EM_DEBUG_EXCEPTION(" unable to evaluate xpath expression [%s]", xpath_configuration_query);
- goto FINISH_OFF;
- }
-
- if(xpath_obj_result_of_query->nodesetval->nodeNr > 0 && xpath_obj_result_of_query->nodesetval->nodeTab) {
- result_content = xmlGetProp(xpath_obj_result_of_query->nodesetval->nodeTab[0] , (const xmlChar *)"value");
- if(result_content) {
- EM_DEBUG_LOG("result_content [%s]", (char*)result_content);
- server_info->protocol_config_array[i].server_addr = strdup((char*)result_content);
- EM_SAFE_FREE(result_content);
- }
- else {
- EM_DEBUG_EXCEPTION("xmlGetProp failed");
- server_info->protocol_config_array[i].server_addr = NULL;
- }
- }
-
- if(xpath_obj_result_of_query) {
- xmlXPathFreeObject(xpath_obj_result_of_query);
- xpath_obj_result_of_query = NULL;
- }
-
- /* searching server address in configuration-parameters element */
-
- sprintf((char*)xpath_configuration_query, "/servicemine/configuration-parameters/configuration[@id=\"%s\"]/wap-provisioningdoc/characteristic/characteristic[@type=\"APPADDR\"]/characteristic[@type=\"PORT\"]/parm", (char*)id_string);
- EM_DEBUG_LOG("[%s]", xpath_configuration_query);
-
- xpath_obj_result_of_query = xmlXPathEvalExpression(xpath_configuration_query, xpath_context);
- if(xpath_obj_result_of_query == NULL) {
- EM_DEBUG_EXCEPTION(" unable to evaluate xpath expression [%s]", (char*)xpath_configuration_query);
- ret_code = EMF_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- if(xpath_obj_result_of_query->nodesetval->nodeNr > 0 && xpath_obj_result_of_query->nodesetval->nodeTab) {
- result_content = xmlGetProp(xpath_obj_result_of_query->nodesetval->nodeTab[0] , (const xmlChar *)"value");
- if(result_content) {
- EM_DEBUG_LOG("result_content [%s]", (char*)result_content);
- server_info->protocol_config_array[i].port_number = atoi((char*)result_content);
- EM_SAFE_FREE(result_content);
- }
- else {
- EM_DEBUG_EXCEPTION("xmlGetProp failed");
- server_info->protocol_config_array[i].port_number = 0;
- }
- }
-
- if(xpath_obj_result_of_query) {
- xmlXPathFreeObject(xpath_obj_result_of_query);
- xpath_obj_result_of_query = NULL;
- }
-
- EM_SAFE_FREE(xpath_configuration_query);
- EM_SAFE_FREE(id_string);
- }
-
- *result_server_info = server_info;
-
-FINISH_OFF:
-
- if(doc)
- xmlFreeDoc(doc);
-
- if(xpath_context)
- xmlXPathFreeContext(xpath_context);
-
- if(xpath_obj_service)
- xmlXPathFreeObject(xpath_obj_service);
-
- if(xpath_obj_configuration)
- xmlXPathFreeObject(xpath_obj_configuration);
-
- if(xpath_obj_result_of_query) {
- xmlXPathFreeObject(xpath_obj_result_of_query);
- xpath_obj_result_of_query = NULL;
}
- xmlCleanupParser(); /* Cleanup function for the XML library. */
-
+FINISH_OFF:
+ if (result_account)
+ emstorage_free_account(&result_account, 1, NULL);
+
EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
- return ret_code;
+ return ret_code;
}
-#endif /* __FEATURE_WDS_SUPPORT__ */
-
-
-INTERNAL_FUNC int emcore_query_server_info(const char* domain_name, emf_server_info_t **result_server_info)
+INTERNAL_FUNC int emcore_recover_from_secured_storage_failure()
{
- EM_DEBUG_FUNC_BEGIN("domain_name [%s], result_server_info [%p]", domain_name, result_server_info);
- int ret_code = EMF_ERROR_NONE;
-#ifdef __FEATURE_WDS_SUPPORT__
- char *result_file_path = NULL;
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+ int i = 0;
+ int account_count = 50;
+ emstorage_account_tbl_t *temp_account_tbl_list = NULL;
+ emstorage_account_tbl_t *temp_account_tbl = NULL;
- if( (ret_code = emcore_fetch_server_info_from_wds(domain_name, &result_file_path)) != EMF_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_fetch_server_info_from_wds failed");
+ if (!emstorage_get_account_list(&account_count, &temp_account_tbl_list, true, false, &err)) {
+ EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
goto FINISH_OFF;
}
- if(result_file_path) {
- if( (ret_code = emcore_parse_server_info_from_wds(result_file_path, result_server_info)) != EMF_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_parse_server_info_from_wds failed");
- goto FINISH_OFF;
- }
- }
-
-FINISH_OFF:
- EM_SAFE_FREE(result_file_path);
-#endif /* __FEATURE_WDS_SUPPORT__ */
- EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
- return ret_code;
-}
-
-
-INTERNAL_FUNC int emcore_free_server_info(emf_server_info_t **target_server_info)
-{
- EM_DEBUG_FUNC_BEGIN("result_server_info [%p]", target_server_info);
- int i, ret_code = EMF_ERROR_NONE;
- emf_server_info_t *server_info = NULL;
-
- if(target_server_info && *target_server_info) {
- server_info = *target_server_info;
- EM_SAFE_FREE(server_info->service_name);
- for(i = 0; i < server_info->protocol_conf_count; i++) {
- EM_SAFE_FREE(server_info->protocol_config_array[i].server_addr);
+ for (i = 0; i < account_count; i++) {
+ if(!emstorage_get_account_by_id(temp_account_tbl_list[i].account_id, EMAIL_ACC_GET_OPT_DEFAULT | EMAIL_ACC_GET_OPT_PASSWORD, &temp_account_tbl, true, &err)) {
+ if(err == EMAIL_ERROR_SECURED_STORAGE_FAILURE) {
+ if(!emcore_delete_account(temp_account_tbl_list[i].account_id, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_delete_account failed [%d]", err);
+ goto FINISH_OFF;
+ }
+ }
}
- EM_SAFE_FREE(server_info->protocol_config_array);
- EM_SAFE_FREE(server_info);
}
- EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
- return ret_code;
-}
-
-INTERNAL_FUNC int emcore_save_default_account_id(int input_account_id)
-{
- EM_DEBUG_FUNC_BEGIN("account_id [%d]", input_account_id);
- int ret_code = EMF_ERROR_NONE, result_value = 0;
- result_value = vconf_set_int(VCONF_KEY_DEFAULT_ACCOUNT_ID, input_account_id);
- if (result_value < 0) {
- EM_DEBUG_EXCEPTION("vconf_set_int failed [%d]", result_value);
- ret_code = EMF_ERROR_SYSTEM_FAILURE;
- }
+FINISH_OFF:
- EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
- return ret_code;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
}
-INTERNAL_FUNC int emcore_load_default_account_id(int *output_account_id)
+INTERNAL_FUNC int emcore_update_sync_status_of_account(int input_account_id, email_set_type_t input_set_operator, int input_sync_status)
{
- EM_DEBUG_FUNC_BEGIN("account_id [%p]", output_account_id);
- int ret_code = EMF_ERROR_NONE, result_value = 0;
-
- if (output_account_id == NULL) {
- ret_code = EMF_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- result_value = vconf_get_int(VCONF_KEY_DEFAULT_ACCOUNT_ID, output_account_id);
+ EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_set_operator [%d], input_sync_status [%d]", input_account_id, input_set_operator, input_sync_status);
+ int err = EMAIL_ERROR_NONE;
- if (result_value < 0) {
- EM_DEBUG_EXCEPTION("vconf_get_int() failed [%d]", result_value);
- ret_code = EMF_ERROR_SYSTEM_FAILURE;
- *output_account_id = 0;
- }
+ if (!emstorage_update_sync_status_of_account(input_account_id, input_set_operator, input_sync_status, true, &err))
+ EM_DEBUG_EXCEPTION("emstorage_update_sync_status_of_account failed [%d]", err);
-FINISH_OFF:
-
- EM_DEBUG_FUNC_END("ret_code [%d]", ret_code);
- return ret_code;
+ EM_DEBUG_FUNC_END("err [%d]", err);
+ return err;
}