summaryrefslogtreecommitdiff
path: root/common/src/email-engine.c
diff options
context:
space:
mode:
authorSungbok Park <parksb@samsung.com>2012-08-21 17:42:03 +0900
committerSungbok Park <parksb@samsung.com>2012-08-21 17:42:03 +0900
commitcf8473c54430527c7a8ab89cf84e05e7d711477b (patch)
treeb29503ce00c1ab948b6cdc96819a2946a6688ca0 /common/src/email-engine.c
parent6f9c7098724e12e1ab06a428efbc21bda28875b0 (diff)
downloademail-cf8473c54430527c7a8ab89cf84e05e7d711477b.tar.gz
email-cf8473c54430527c7a8ab89cf84e05e7d711477b.tar.bz2
email-cf8473c54430527c7a8ab89cf84e05e7d711477b.zip
org.tizen.email-0.0.1 release
Diffstat (limited to 'common/src/email-engine.c')
-rwxr-xr-xcommon/src/email-engine.c263
1 files changed, 263 insertions, 0 deletions
diff --git a/common/src/email-engine.c b/common/src/email-engine.c
new file mode 100755
index 0000000..91d8eb9
--- /dev/null
+++ b/common/src/email-engine.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ctype.h>
+#include <string.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <email-api.h>
+#include <db-util.h>
+#include <vconf.h>
+
+#include "email-common-types.h"
+#include "email-debug.h"
+#include "email-utils.h"
+#include "email-engine.h"
+
+#define ACCOUNT_MIN -1
+
+static guint _g_edb_ref_count = 0;
+
+
+gboolean email_engine_initialize(void)
+{
+ debug_log("");
+ ++_g_edb_ref_count;
+
+ if (_g_edb_ref_count > 1) {
+ debug_log("already opened - EDB ref_count(%d)", _g_edb_ref_count);
+ return TRUE;
+ }
+
+ int err = 0;
+
+ debug_log("email_service_begin");
+
+ /*err = ipcEmailProxy_Initialize(0);*/
+ err = email_service_begin();
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to email_service_begin - err(%d)", err);
+ /*
+ g_assert(0);
+ */
+ return FALSE;
+ }
+
+ err = email_open_db();
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to open db - err(%d)", err);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void email_engine_finalize(void)
+{
+ debug_log("");
+ --_g_edb_ref_count;
+
+ if (_g_edb_ref_count > 0) {
+ debug_log("remain EDB ref_count(%d)", _g_edb_ref_count);
+ return;
+ }
+
+ int err = 0;
+
+ err = email_close_db();
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to close db - err(%d)", err);
+ }
+
+ debug_log("email_service_end");
+
+ err = email_service_end();
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to email_service_end - err(%d)", err);
+ }
+}
+
+gboolean email_engine_get_account_full_data(int acctid, email_account_t **account)
+{
+ debug_log("");
+ debug_log("email_engine_get_account_full_data. acctid:%d", acctid);
+ RETURN_VAL_IF_FAIL(acctid > ACCOUNT_MIN, FALSE);
+ int err = 0;
+
+ err = email_get_account(acctid, EMAIL_ACC_GET_OPT_FULL_DATA, account);
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("email_get_account full data error Err(%d)", err);
+ return FALSE;
+ }
+ if (*account) {
+ debug_log("Account name: %s", (*account)->account_name);
+ if ((*account)->options.signature)
+ debug_log("Signature: %s", (*account)->options.signature);
+ } else {
+ debug_critical("account is NULL");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean email_engine_set_default_account(gint account_id)
+{
+ debug_log("");
+ RETURN_VAL_IF_FAIL(account_id > ACCOUNT_MIN, FALSE);
+ int err = 0;
+
+ err = email_save_default_account_id(account_id);
+ debug_log("email_save_default_account_id returns %d.", err);
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("email_save_default_account_id: Err(%d)", err);
+ return FALSE;
+ } else {
+ debug_log("default account is set as account_id %d.", account_id);
+ return TRUE;
+ }
+}
+
+gboolean email_engine_get_default_account(gint *account_id)
+{
+ debug_log("");
+ RETURN_VAL_IF_FAIL(account_id != NULL, FALSE);
+
+ email_account_t *_account = NULL;
+ int count = 0;
+ int err = 0;
+
+ err = email_load_default_account_id(account_id);
+ debug_log("email_load_default_account_id returns %d.", err);
+
+ /* if account_id is default account, then check account_id whether it is valid or not */
+ if (err == EMAIL_ERROR_NONE) {
+ debug_log("default account id is %d.", *account_id);
+ if (email_get_account(*account_id, EMAIL_ACC_GET_OPT_DEFAULT, &_account) == EMAIL_ERROR_NONE) {
+ email_free_account(&_account, 1);
+ return TRUE;
+ }
+ }
+
+ /* if slp_ret have no value or account id is not valid */
+ err = email_get_account_list(&_account, &count);
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to get account list - err(%d)", err);
+ return FALSE;
+ }
+
+ /* no account */
+ if (_account == NULL || count == 0) {
+ debug_log("account info is null");
+ return FALSE;
+ }
+
+ *account_id = _account[0].account_id;
+ debug_log("account id (%d)", *account_id);
+
+ err = email_free_account(&_account, count);
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to free account - err(%d)", err);
+ return FALSE;
+ }
+
+ RETURN_VAL_IF_FAIL((*account_id) > 0, FALSE);
+ email_engine_set_default_account(*account_id);
+
+ return TRUE;
+}
+
+void email_engine_stop_working(gint account_id, unsigned handle)
+{
+ debug_log("");
+
+ RETURN_IF_FAIL(account_id > ACCOUNT_MIN);
+ RETURN_IF_FAIL(handle > 0);
+
+ int err = 0;
+
+ debug_log("handle (%d)", handle);
+
+ err = email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER);
+
+ if (err != EMAIL_ERROR_NONE) {
+ debug_warning("fail to cancel job");
+ }
+}
+
+gboolean email_engine_delete_mail(gint account_id, int mailbox_id, gint mail_id, int sync)
+{
+ debug_log("");
+ RETURN_VAL_IF_FAIL(account_id > ACCOUNT_MIN, FALSE);
+ RETURN_VAL_IF_FAIL(mailbox_id > 0, FALSE);
+ RETURN_VAL_IF_FAIL(mail_id > 0, FALSE);
+
+ int err = 0;
+ int mail_ids[1] = { 0 };
+ gboolean res = TRUE; /* MUST BE initialized TRUE. */
+
+ mail_ids[0] = mail_id;
+
+ debug_log("account_id : %d", account_id);
+ debug_log("mail_ids[0] : %d", mail_ids[0]);
+ debug_log("sync : %d", sync);
+ err = email_delete_mail(mailbox_id, mail_ids, 1, sync);
+
+ if (err != EMAIL_ERROR_NONE) {
+ debug_warning("failed to delete message - err (%d)", err);
+ res = FALSE;
+ }
+
+ return res;
+}
+
+gchar *email_engine_get_attachment_path(gint attach_id)
+{
+ debug_log("");
+ RETURN_VAL_IF_FAIL(attach_id > 0, FALSE);
+
+ int err = 0;
+ email_attachment_data_t *attachments = NULL;
+ gchar *attachment_path = NULL;
+
+ err = email_get_attachment_data(attach_id, &attachments);
+
+ if (err != EMAIL_ERROR_NONE) {
+ debug_critical("fail to get attachment info - err (%d)", err);
+ goto error;
+ }
+
+ if (attachments == NULL) {
+ debug_critical("attachments is @niL");
+ goto error;
+ }
+
+ if (STR_VALID(attachments->attachment_path)) {
+ debug_log("attachment path (%s)", attachments->attachment_path);
+ attachment_path = g_strdup(attachments->attachment_path);
+ }
+
+ err = email_free_attachment_data(&attachments, 1);
+
+ if (err != EMAIL_ERROR_NONE) {
+ debug_warning("fail to free attachment info - err(%d)", err);
+ }
+
+ error:
+ return attachment_path;
+}
+
+/* EOF */