summaryrefslogtreecommitdiff
path: root/email-engine/emf-etc.c
blob: b615b12d7242b1f69b2119bc2e3652a12e3bbe54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
*  email-service
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/



/******************************************************************************
 * File: emf-etc.c
 * Desc: Mail Framework Etc Implementations
 *
 * Auth:
 *
 * History:
 *    2006.08.16 : created
 *****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vconf.h>
#include "emflib.h"
#include "emf-account.h"
#include "emf-dbglog.h"
#include "emf-global.h"
#include "em-core-types.h"
#include "em-core-event.h"
#include "em-core-utils.h"
#include "em-storage.h"


int emf_register_event_callback(emf_action_t action, emf_event_callback callback, void* event_data)
{
	return em_core_register_event_callback(action, callback, event_data);
}

int emf_unregister_event_callback(emf_action_t action, emf_event_callback callback)
{
	return em_core_unregister_event_callback(action, callback);
}


EXPORT_API void emf_get_event_queue_status(int* on_sending, int* on_receiving)
{
	em_core_get_event_queue_status(on_sending, on_receiving);
}

EXPORT_API int emf_get_pending_job(emf_action_t action, int account_id, int mail_id, emf_event_status_type_t* status)
{
	EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d]", action, account_id, mail_id);

	return em_core_get_pending_event(action, account_id, mail_id, status);
}

EXPORT_API int emf_cancel_job(int account_id, int handle, int* err_code)
{
	EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%d], err_code[%p]", account_id, handle, err_code);
	
	int ret = false;
	int err = EMF_ERROR_NONE;
	
	
	if (!em_core_cancel_thread(handle, NULL, &err))  {
		EM_DEBUG_EXCEPTION("em_core_cancel_thread failed [%d]", err);
		goto FINISH_OFF;
	}
	
	ret = true;
	
FINISH_OFF:
	if (err_code != NULL)
		*err_code = err;
	EM_DEBUG_FUNC_END();
	return ret;
}


EXPORT_API int emf_mail_send_mail_cancel_job(int account_id, int mail_id, int* err_code)
{
	EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], err_code[%p]", account_id, mail_id, err_code);
	
	int ret = false;
	int err = EMF_ERROR_NONE;	
	int handle = 0;
	emf_account_t* ref_account = NULL;
	
	if (account_id <= 0)  {
		EM_DEBUG_EXCEPTION("account_id[%d], mail_id[%d]", account_id, mail_id);
		err = EMF_ERROR_INVALID_PARAM;
		goto FINISH_OFF;
	}

#ifdef __FEATURE_PROGRESS_IN_OUTBOX__

	/*	h.gahlaut@samsung.com: Moved this code from email_cancel_send_mail API to email-service engine
		since this code has update DB operation which is failing in context of email application process 
		with an sqlite error -> sqlite3_step fail:8 */
		
	/* 	which means #define SQLITE_READONLY   8 */  /* Attempt to write a readonly database */ 
	emf_mail_t* mail = NULL;

	if (!em_core_mail_get_mail(mail_id, &mail, &err))  {
		EM_DEBUG_EXCEPTION("em_core_mail_get_mail failed [%d]", err);
		goto FINISH_OFF;
	}

	if (mail && mail->info) {
		if (mail->info->extra_flags.status == EMF_MAIL_STATUS_SEND_CANCELED) {
			EM_DEBUG_EXCEPTION(">>>> EMF_MAIL_STATUS_SEND_CANCELED Already set for Mail ID [ %d ]", mail_id);
			goto FINISH_OFF;
		}
		else {			
			mail->info->extra_flags.status = EMF_MAIL_STATUS_SEND_CANCELED;

			if(!em_core_mail_modify_extra_flag(mail_id, mail->info->extra_flags, &err)) {
				EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]",err);
				goto FINISH_OFF;
			}
		}
	}

#endif

	if(!em_core_get_handle_by_mailId_from_transaction_info(mail_id , &handle )) {
		EM_DEBUG_EXCEPTION("em_core_get_handle_by_mailId_from_transaction_info failed for mail_id[%d]", mail_id);
		err = EMF_ERROR_HANDLE_NOT_FOUND;
		goto FINISH_OFF;
	}

	if (!(ref_account = emf_get_account_reference(account_id)))  {
		EM_DEBUG_EXCEPTION("emf_get_account_reference failed [%d]", account_id);
		err = EMF_ERROR_INVALID_ACCOUNT;
		goto FINISH_OFF;
	}

	switch (ref_account->account_bind_type)  {
		case EMF_BIND_TYPE_EM_CORE :
			if (!em_core_cancel_send_mail_thread(handle, NULL, &err))  {
				EM_DEBUG_EXCEPTION("em_core_cancel_send_mail_thread failed [%d]", err);
				goto FINISH_OFF;
			}
			break;

		default:
			EM_DEBUG_EXCEPTION("unknown account bind type...");
			err = EMF_ERROR_INVALID_ACCOUNT;
			goto FINISH_OFF;
	}	
	
	if(!em_core_delete_transaction_info_by_mailId(mail_id))
		EM_DEBUG_EXCEPTION("em_core_delete_transaction_info_by_mailId failed for mail_id[%d]", mail_id);
	
	ret = true;
	
FINISH_OFF:
	if(err_code != NULL)
		*err_code = err;
	
#ifdef __FEATURE_PROGRESS_IN_OUTBOX__
	if(!em_core_mail_free(&mail, 1, &err))
		EM_DEBUG_EXCEPTION("em_core_mail_free Failed [%d ]", err);	

#endif
	EM_DEBUG_FUNC_END();
	return ret;
}	


EXPORT_API int
emf_clear_mail_data(int* err_code)
{
	EM_DEBUG_FUNC_BEGIN();
	
	int ret = false;
	int error = EMF_ERROR_NONE;
	
	if (emf_init(&error)) {
		if (!em_storage_clear_mail_data(true, &error))
			EM_DEBUG_EXCEPTION("em_storage_clear_mail_data failed [%d]", error);
	}
	else {
		EM_DEBUG_EXCEPTION("emf_init failed [%d]", error);
		if (err_code)
			*err_code = error;
		return false;
	}

	em_core_check_unread_mail();

	ret = true;

	if (!em_storage_create_table(EMF_CREATE_DB_NORMAL, &error)) 
		EM_DEBUG_EXCEPTION("em_storage_create_table failed [%d]", error);
	
	emf_close(&error);
	
	if (err_code)
		*err_code = error;
	EM_DEBUG_FUNC_END();
    return ret;
}

	
/* --------------------------------------------------------------------------------*/