4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 /******************************************************************************
26 * Desc: Mail Framework Etc Implementations
31 * 2006.08.16 : created
32 *****************************************************************************/
38 #include "emf-account.h"
39 #include "emf-dbglog.h"
40 #include "emf-global.h"
41 #include "em-core-types.h"
42 #include "em-core-event.h"
43 #include "em-core-utils.h"
44 #include "em-storage.h"
47 int emf_register_event_callback(emf_action_t action, emf_event_callback callback, void* event_data)
49 return em_core_register_event_callback(action, callback, event_data);
52 int emf_unregister_event_callback(emf_action_t action, emf_event_callback callback)
54 return em_core_unregister_event_callback(action, callback);
58 EXPORT_API void emf_get_event_queue_status(int* on_sending, int* on_receiving)
60 em_core_get_event_queue_status(on_sending, on_receiving);
63 EXPORT_API int emf_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t* status)
65 EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d]", action, account_id, mail_id);
67 return em_core_get_pending_event(action, account_id, mail_id, status);
70 EXPORT_API int emf_cancel_job(int account_id, int handle, int* err_code)
72 EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%d], err_code[%p]", account_id, handle, err_code);
75 int err = EMF_ERROR_NONE;
78 if (!em_core_cancel_thread(handle, NULL, &err)) {
79 EM_DEBUG_EXCEPTION("em_core_cancel_thread failed [%d]", err);
93 EXPORT_API int emf_mail_send_mail_cancel_job(int account_id, int mail_id, int* err_code)
95 EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
98 int err = EMF_ERROR_NONE;
100 emf_account_t* ref_account = NULL;
102 if (account_id <= 0) {
103 EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d]", account_id, mail_id);
104 err = EMF_ERROR_INVALID_PARAM;
108 #ifdef __FEATURE_PROGRESS_IN_OUTBOX__
110 /* h.gahlaut@samsung.com: Moved this code from email_cancel_send_mail API to email-service engine
111 since this code has update DB operation which is failing in context of email application process
112 with an sqlite error -> sqlite3_step fail:8 */
114 /* which means #define SQLITE_READONLY 8 */ /* Attempt to write a readonly database */
115 emf_mail_t* mail = NULL;
117 if (!em_core_mail_get_mail(mail_id, &mail, &err)) {
118 EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
122 if (mail && mail->info) {
123 if (mail->info->extra_flags.status == EMF_MAIL_STATUS_SEND_CANCELED) {
124 EM_DEBUG_EXCEPTION(">>>> EMF_MAIL_STATUS_SEND_CANCELED Already set for Mail ID [ %d ]", mail_id);
128 mail->info->extra_flags.status = EMF_MAIL_STATUS_SEND_CANCELED;
130 if(!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err)) {
131 EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]",err);
139 if(!em_core_get_handle_by_mailId_from_transaction_info(mail_id , &handle )) {
140 EM_DEBUG_EXCEPTION("em_core_get_handle_by_mailId_from_transaction_info failed for mail_id[%d]", mail_id);
141 err = EMF_ERROR_HANDLE_NOT_FOUND;
145 if (!(ref_account = emf_get_account_reference(account_id))) {
146 EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
147 err = EMF_ERROR_INVALID_ACCOUNT;
151 switch (ref_account->account_bind_type) {
152 case EMF_BIND_TYPE_EM_CORE :
153 if (!em_core_cancel_send_mail_thread(handle, NULL, &err)) {
154 EM_DEBUG_EXCEPTION("em_core_cancel_send_mail_thread failed [%d]", err);
160 EM_DEBUG_EXCEPTION("unknown account bind type...");
161 err = EMF_ERROR_INVALID_ACCOUNT;
165 if(!em_core_delete_transaction_info_by_mailId(mail_id))
166 EM_DEBUG_EXCEPTION("em_core_delete_transaction_info_by_mailId failed for mail_id[%d]", mail_id);
174 #ifdef __FEATURE_PROGRESS_IN_OUTBOX__
175 if(!em_core_mail_free(&mail, 1, &err))
176 EM_DEBUG_EXCEPTION("em_core_mail_free Failed [%d ]", err);
185 emf_clear_mail_data(int* err_code)
187 EM_DEBUG_FUNC_BEGIN();
190 int error = EMF_ERROR_NONE;
192 if (emf_init(&error)) {
193 if (!em_storage_clear_mail_data(true, &error))
194 EM_DEBUG_EXCEPTION("em_storage_clear_mail_data failed [%d]", error);
197 EM_DEBUG_EXCEPTION("emf_init failed [%d]", error);
203 em_core_check_unread_mail();
207 if (!em_storage_create_table(EMF_CREATE_DB_NORMAL, &error))
208 EM_DEBUG_EXCEPTION("em_storage_create_table failed [%d]", error);
219 /* --------------------------------------------------------------------------------*/