Tizen 2.0 Release
[platform/core/messaging/email-service.git] / email-api / email-api-account.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 */
21
22
23 /**
24  *
25  * This file contains the data structures and interfaces needed for application,
26  * to interact with email-service.
27  * @file                email-api-account.c
28  * @brief               This file contains the data structures and interfaces of Account related Functionality provided by
29  *                      email-service .
30  */
31
32 #include "email-api.h"
33 #include "string.h"
34 #include "email-convert.h"
35 #include "email-api-account.h"
36 #include "email-storage.h"
37 #include "email-core-mail.h"
38 #include "email-core-account.h"
39 #include "email-core-utils.h"
40 #include "email-utilities.h"
41 #include "email-ipc.h"
42
43 /* API - Adds the Email Account */
44 EXPORT_API int email_add_account(email_account_t* account)
45 {
46         EM_DEBUG_FUNC_BEGIN("account[%p]", account);
47         char* local_account_stream = NULL;
48         int size = 0;
49         int err = EMAIL_ERROR_NONE;
50         int ret_from_ipc = EMAIL_ERROR_NONE;
51         HIPC_API hAPI = NULL;
52
53         if ( !account )  {
54                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
55                 return EMAIL_ERROR_INVALID_PARAM;
56         }
57
58         /* composing account information to be added */
59         hAPI = emipc_create_email_api(_EMAIL_API_ADD_ACCOUNT);
60         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
61
62         local_account_stream = em_convert_account_to_byte_stream(account, &size);
63         EM_PROXY_IF_NULL_RETURN_VALUE(local_account_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
64
65         if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, local_account_stream, size)) {
66                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
67                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
68         }
69         EM_DEBUG_LOG("APPID[%d], APIID [%d]", emipc_get_app_id(hAPI), emipc_get_api_id(hAPI));
70
71         /* passing account information to service */
72         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
73                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
74                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
75         }
76
77         /* get result from service */
78         if( (ret_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err)) != EMAIL_ERROR_NONE) {
79                 EM_DEBUG_EXCEPTION("emipc_get_parameter failed [%d]", ret_from_ipc);
80                 err = ret_from_ipc;
81                 goto FINISH_OFF;
82         }
83
84         if(err == EMAIL_ERROR_NONE) {
85                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &account->account_id);
86         }
87         else {  /*  get error code */
88                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
89         }
90
91 FINISH_OFF:
92
93         if(hAPI)
94                 emipc_destroy_email_api(hAPI);
95
96         EM_DEBUG_FUNC_END("ERROR CODE [%d]", err);
97         return err;
98 }
99
100
101 EXPORT_API int email_free_account(email_account_t** account_list, int count)
102 {
103         EM_DEBUG_FUNC_BEGIN("account_list[%p], count[%d]", account_list, count);
104
105         /*  default variable */
106         int err = EMAIL_ERROR_NONE;
107
108         if (count > 0)  {
109                 if (!account_list || !*account_list)  {
110                         err = EMAIL_ERROR_INVALID_PARAM;
111                         goto FINISH_OFF;
112                 }
113                 email_account_t* p = *account_list;
114                 int i;
115
116                 for (i = 0; i < count; i++)  {
117                         EM_SAFE_FREE(p[i].account_name);
118                         EM_SAFE_FREE(p[i].incoming_server_address);
119                         EM_SAFE_FREE(p[i].user_email_address);
120                         EM_SAFE_FREE(p[i].incoming_server_user_name);
121                         EM_SAFE_FREE(p[i].incoming_server_password);
122                         EM_SAFE_FREE(p[i].outgoing_server_address);
123                         EM_SAFE_FREE(p[i].outgoing_server_user_name);
124                         EM_SAFE_FREE(p[i].outgoing_server_password);
125                         EM_SAFE_FREE(p[i].user_display_name);
126                         EM_SAFE_FREE(p[i].reply_to_address);
127                         EM_SAFE_FREE(p[i].return_address);
128                         EM_SAFE_FREE(p[i].logo_icon_path);
129                         EM_SAFE_FREE(p[i].user_data);
130                         p[i].user_data_length = 0;
131                         EM_SAFE_FREE(p[i].options.display_name_from);
132                         EM_SAFE_FREE(p[i].options.signature);
133                 }
134                 free(p); *account_list = NULL;
135         }
136
137 FINISH_OFF:
138         EM_DEBUG_FUNC_END("ERROR CODE [%d]", err);
139         return err;
140 }
141
142
143 /* API - Delete  the Email Account */
144 EXPORT_API int email_delete_account(int account_id)
145 {
146         EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id);
147
148         int ret = 0;
149         int err = EMAIL_ERROR_NONE;
150
151         if (account_id < 0 || account_id == 0)  {
152                 EM_DEBUG_EXCEPTION(" account_id[%d]", account_id);
153                 err = EMAIL_ERROR_INVALID_PARAM;
154                 return err;
155         }
156
157         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_ACCOUNT);
158
159         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
160
161         /* account_id */
162         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
163                 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id  failed ");
164                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
165         }
166
167         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
168                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed ");
169                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
170         }
171
172         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
173         if(ret != EMAIL_ERROR_NONE) {   /*  get error code */
174                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
175         }
176         emipc_destroy_email_api(hAPI);
177
178         hAPI = NULL;
179         EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
180         return err;
181 }
182
183 /* API - Update  the Email Account */
184 EXPORT_API int email_update_account(int account_id, email_account_t* new_account)
185 {
186         EM_DEBUG_FUNC_BEGIN("account_id[%d], new_account[%p]", account_id, new_account);
187
188         int ret = 0;
189         int size = 0;
190         int err = EMAIL_ERROR_NONE;
191         int with_validation = false;
192         char* new_account_stream = NULL;
193
194         if ( account_id <= 0 || !new_account )  { /*prevent 23138*/
195                 EM_DEBUG_EXCEPTION("account_id[%d], new_account[%p], with_validation[%d]", account_id, new_account, with_validation);
196                 return  EMAIL_ERROR_INVALID_PARAM;
197         }
198
199         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_UPDATE_ACCOUNT);
200
201         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
202
203         /* account_id */
204         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
205                 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
206                 goto FINISH_OFF;
207         }
208
209         /* new_account */
210         new_account_stream = em_convert_account_to_byte_stream(new_account, &size);
211         EM_PROXY_IF_NULL_RETURN_VALUE(new_account_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
212         if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, new_account_stream, size)) {
213                 EM_DEBUG_EXCEPTION("emipc_add_parameter new_account failed ");
214                 goto FINISH_OFF;
215         }
216
217         /* with_validation */
218         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&with_validation, sizeof(int))) {
219                 EM_DEBUG_EXCEPTION("emipc_add_parameter with_validation failed ");
220                 goto FINISH_OFF;
221         }
222
223         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
224                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
225                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
226         }
227
228         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
229         if(ret != EMAIL_ERROR_NONE) {
230                 /*  get error code */
231                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
232         }
233
234 FINISH_OFF:
235
236         emipc_destroy_email_api(hAPI);
237         hAPI = NULL;
238
239         EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
240         return err;
241 }
242
243 /* API - Update  the Email Account */
244 EXPORT_API int email_update_account_with_validation(int account_id, email_account_t* new_account)
245 {
246         EM_DEBUG_FUNC_BEGIN("account_id[%d], new_account[%p]", account_id, new_account);
247
248         int ret = 0;
249         int size = 0;
250         int err = EMAIL_ERROR_NONE;
251         int with_validation = true;
252         char* new_account_stream = NULL;
253
254         if ((account_id <= 0) || !new_account || (with_validation != false && with_validation != true))  {
255                 EM_DEBUG_EXCEPTION(" account_id[%d], new_account[%p], with_validation[%d]", account_id, new_account, with_validation);
256                 err = EMAIL_ERROR_INVALID_PARAM;
257                 return err;
258         }
259
260         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_UPDATE_ACCOUNT);
261
262         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
263
264         /* account_id */
265         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
266                 EM_DEBUG_EXCEPTION("email_update_account--emipc_add_parameter account_id  failed ");
267                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
268         }
269
270         /* new_account */
271         new_account_stream = em_convert_account_to_byte_stream(new_account, &size);
272         EM_PROXY_IF_NULL_RETURN_VALUE(new_account_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
273         if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, new_account_stream, size)) {
274                 EM_DEBUG_EXCEPTION("email_update_account--emipc_add_parameter new_account  failed ");
275                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
276         }
277
278         /* with_validation */
279         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&with_validation, sizeof(int))) {
280                 EM_DEBUG_EXCEPTION("email_update_account--emipc_add_parameter with_validation  failed ");
281                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
282         }
283
284         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
285                 EM_DEBUG_EXCEPTION("email_update_account--emipc_execute_proxy_api failed ");
286                 /* Prevent defect 18624 */
287                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
288         }
289
290         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
291         if(ret != EMAIL_ERROR_NONE) {   /*  get error code */
292                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
293         }
294
295         emipc_destroy_email_api(hAPI);
296         hAPI = NULL;
297
298         EM_DEBUG_FUNC_END("RETURN VALUE [%d], ERROR CODE [%d]", ret, err);
299         return err;
300 }
301
302
303 /* API - Get the account Information based on the account ID */
304 EXPORT_API int email_get_account(int account_id, int pulloption, email_account_t** account)
305 {
306         EM_DEBUG_FUNC_BEGIN();
307         int ret = 0;
308         int err = EMAIL_ERROR_NONE;
309         emstorage_account_tbl_t *account_tbl = NULL;
310
311         EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
312         EM_IF_NULL_RETURN_VALUE(account, EMAIL_ERROR_INVALID_PARAM);
313
314         if (pulloption == GET_FULL_DATA)
315                 pulloption = EMAIL_ACC_GET_OPT_FULL_DATA;
316
317         if (pulloption & EMAIL_ACC_GET_OPT_PASSWORD) {
318                 pulloption = pulloption & (~(EMAIL_ACC_GET_OPT_PASSWORD));      /*  disable password -Can't obtain password by MAPI */
319                 EM_DEBUG_LOG("change pulloption : disable password");
320         }
321
322         if (!emstorage_get_account_by_id(account_id, pulloption, &account_tbl, true, &err)) {
323                 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed - %d", err);
324                 goto FINISH_OFF;
325         }
326
327         *account = em_malloc(sizeof(email_account_t));
328         if (!*account) {
329                 EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
330                 goto FINISH_OFF;
331         }
332         memset((void*)*account, 0, sizeof(email_account_t));
333         em_convert_account_tbl_to_account(account_tbl, *account);
334
335
336         ret = true;
337
338 FINISH_OFF:
339         if (account_tbl)
340                 emstorage_free_account(&account_tbl, 1, NULL);
341
342         EM_DEBUG_FUNC_END();
343         return err;
344 }
345
346 EXPORT_API int email_get_account_list(email_account_t** account_list, int* count)
347 {
348         EM_DEBUG_FUNC_BEGIN();
349
350         int err = EMAIL_ERROR_NONE, i = 0;
351         emstorage_account_tbl_t *temp_account_tbl = NULL;
352
353         EM_IF_NULL_RETURN_VALUE(account_list, EMAIL_ERROR_INVALID_PARAM);
354         EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
355
356         if (!emstorage_get_account_list(count, &temp_account_tbl , true, false, &err)) {
357                 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
358
359                 goto FINISH_OFF;
360         }
361
362         if(temp_account_tbl && (*count) > 0) {
363                 *account_list = em_malloc(sizeof(email_account_t) * (*count));
364                 if(!*account_list) {
365                         EM_DEBUG_EXCEPTION("allocation failed [%d]", err);
366                         goto FINISH_OFF;
367                 }
368                 memset((void*)*account_list, 0, sizeof(email_account_t) * (*count));
369                 for(i = 0; i < (*count); i++)
370                         em_convert_account_tbl_to_account(temp_account_tbl + i, (*account_list) + i);
371         }
372
373 FINISH_OFF:
374
375
376         if(temp_account_tbl)
377                 emstorage_free_account(&temp_account_tbl, (*count), NULL);
378         EM_DEBUG_FUNC_END("err[%d]", err);
379         return err;
380
381 }
382
383 EXPORT_API int email_validate_account(int account_id, int *handle)
384 {
385         EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p]", account_id, handle);
386
387         int ret = 0;
388         int err = EMAIL_ERROR_NONE;
389         if (account_id <= 0)  {
390                 EM_DEBUG_EXCEPTION("account_id[%d]", account_id);
391                 err = EMAIL_ERROR_INVALID_PARAM;
392                 return err;
393         }
394
395         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VALIDATE_ACCOUNT);
396
397         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
398
399         /* account_id */
400         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
401                 EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id  failed ");
402                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
403         }
404
405         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
406                 EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
407                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
408         }
409
410         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret); /*  return  */
411         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err); /*  error code */
412
413         if(handle)
414                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), handle);
415
416         emipc_destroy_email_api(hAPI);
417
418         hAPI = NULL;
419         EM_DEBUG_FUNC_END("err[%d]", err);
420         return err;
421
422 }
423
424
425 EXPORT_API int email_add_account_with_validation(email_account_t* account, int *handle)
426 {
427         EM_DEBUG_FUNC_BEGIN("account[%p]", account);
428         char* local_account_stream = NULL;
429         int ret = -1;
430         int size = 0;
431         int err = EMAIL_ERROR_NONE;
432
433         EM_IF_NULL_RETURN_VALUE(account, false);
434
435         if(emstorage_check_duplicated_account(account, true, &err) == false) {
436                 EM_DEBUG_EXCEPTION("emstorage_check_duplicated_account failed (%d) ", err);
437                 return err;
438         }
439
440         /* create account information */
441         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_ACCOUNT_WITH_VALIDATION);
442         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
443
444         local_account_stream = em_convert_account_to_byte_stream(account, &size);
445         EM_PROXY_IF_NULL_RETURN_VALUE(local_account_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
446         if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, local_account_stream, size)) {
447                 EM_DEBUG_EXCEPTION(" emipc_add_parameter  failed ");
448                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
449         }
450
451         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
452                 EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
453                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
454         }
455
456         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
457         if(ret == EMAIL_ERROR_NONE) {
458                 if(handle)
459                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
460         } else {
461                 /*  get error code */
462                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
463         }
464
465         emipc_destroy_email_api(hAPI);
466         hAPI = NULL;
467
468         EM_DEBUG_FUNC_END("err[%d]", err);
469         return err;
470 }
471
472
473 EXPORT_API int email_backup_accounts_into_secure_storage(const char *file_name)
474 {
475         EM_DEBUG_FUNC_BEGIN("file_name[%s]", file_name);
476         int ret = 0;
477         int err = EMAIL_ERROR_NONE;
478
479         if (!file_name)  {
480                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
481                 err = EMAIL_ERROR_INVALID_PARAM;
482                 return err;
483         }
484
485         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_BACKUP_ACCOUNTS);
486
487         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
488
489         /* file_name */
490         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) {
491                 EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id  failed ");
492                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
493         }
494
495         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
496                 EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
497                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
498         }
499
500         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
501
502         if(0 == ret) {  /*  get error code */
503                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
504         }
505
506         emipc_destroy_email_api(hAPI);
507
508         hAPI = NULL;
509         EM_DEBUG_FUNC_END("err[%d]", err);
510         return err;
511 }
512
513 EXPORT_API int email_restore_accounts_from_secure_storage(const char * file_name)
514 {
515         EM_DEBUG_FUNC_BEGIN("file_name[%s]", file_name);
516         int ret = 0;
517         int err = EMAIL_ERROR_NONE;
518
519         if (!file_name)  {
520                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
521                 err = EMAIL_ERROR_INVALID_PARAM;
522                 return err;
523         }
524
525         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_RESTORE_ACCOUNTS);
526
527         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
528
529         /* file_name */
530         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)file_name, EM_SAFE_STRLEN(file_name)+1)) {
531                 EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id  failed ");
532                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
533         }
534
535         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
536                 EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
537                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
538         }
539
540         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
541
542         if(0==ret) {    /*  get error code */
543                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
544         }
545
546         emipc_destroy_email_api(hAPI);
547
548         hAPI = NULL;
549         EM_DEBUG_FUNC_END("err[%d]", err);
550         return err;
551 }
552
553 EXPORT_API int email_get_password_length_of_account(const int account_id, int *password_length)
554 {
555         EM_DEBUG_FUNC_BEGIN("account_id[%d], password_length[%p]", account_id, password_length);
556         int ret = 0;
557         int err = EMAIL_ERROR_NONE;
558
559         if (account_id <= 0 || password_length == NULL)  {
560                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
561                 err = EMAIL_ERROR_INVALID_PARAM;
562                 return err;
563         }
564
565         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_PASSWORD_LENGTH_OF_ACCOUNT);
566
567         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
568
569         /* account_id */
570         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
571                 EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id  failed ");
572                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
573         }
574
575         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
576                 EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
577                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
578         }
579
580         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &ret);
581         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &err);
582         emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), password_length);
583
584         emipc_destroy_email_api(hAPI);
585
586         hAPI = NULL;
587         EM_DEBUG_FUNC_END("*password_length[%d]", *password_length);
588         return err;
589 }
590
591 EXPORT_API int email_query_server_info(const char* domain_name, email_server_info_t **result_server_info)
592 {
593         EM_DEBUG_FUNC_BEGIN("domain_name [%s], result_server_info [%p]", domain_name, result_server_info);
594         int err = EMAIL_ERROR_NONE;
595
596         if (!domain_name || !result_server_info)  {
597                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
598                 err = EMAIL_ERROR_INVALID_PARAM;
599                 return err;
600         }
601
602         err = emcore_query_server_info(domain_name, result_server_info);
603
604         EM_DEBUG_FUNC_END("err[%d]", err);
605         return err;
606 }
607
608
609 EXPORT_API int email_free_server_info(email_server_info_t **result_server_info)
610 {
611         EM_DEBUG_FUNC_BEGIN("result_server_info [%p]", result_server_info);
612         int err = EMAIL_ERROR_NONE;
613
614         if (!result_server_info)  {
615                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
616                 err = EMAIL_ERROR_INVALID_PARAM;
617                 return err;
618         }
619
620         err = emcore_free_server_info(result_server_info);
621
622         EM_DEBUG_FUNC_END("ret[%d]", err);
623         return err;
624 }
625
626 EXPORT_API int email_update_notification_bar(int account_id)
627 {
628         EM_DEBUG_FUNC_BEGIN("account_id [%d]", account_id);
629         int err = EMAIL_ERROR_NONE;
630
631         if (account_id == 0)  {
632                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
633                 err = EMAIL_ERROR_INVALID_PARAM;
634                 return err;
635         }
636
637         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_UPDATE_NOTIFICATION_BAR_FOR_UNREAD_MAIL);
638
639         EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
640
641         /* account_id */
642         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
643                 EM_DEBUG_EXCEPTION(" emipc_add_parameter account_id  failed");
644                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
645         }
646
647         if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
648                 EM_DEBUG_EXCEPTION(" emipc_execute_proxy_api failed ");
649                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
650         }
651
652         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
653         emipc_destroy_email_api(hAPI);
654
655         hAPI = NULL;
656         EM_DEBUG_FUNC_END("ret[%d]", err);
657         return err;
658 }
659
660
661 EXPORT_API int email_clear_all_notification_bar()
662 {
663         EM_DEBUG_FUNC_BEGIN();
664         int err = EMAIL_ERROR_NONE;
665
666         err = emcore_clear_all_notifications();
667
668         EM_DEBUG_FUNC_END("ret[%d]", err);
669         return err;
670 }
671
672 EXPORT_API int email_save_default_account_id(int input_account_id)
673 {
674         EM_DEBUG_FUNC_BEGIN("input_account_id [%d]", input_account_id);
675         int err = EMAIL_ERROR_NONE;
676
677         err = emcore_save_default_account_id(input_account_id);
678
679         EM_DEBUG_FUNC_END("ret[%d]", err);
680         return err;
681 }
682
683 EXPORT_API int email_load_default_account_id(int *output_account_id)
684 {
685         EM_DEBUG_FUNC_BEGIN("output_account_id [%p]", output_account_id);
686         int err = EMAIL_ERROR_NONE;
687
688         err = emcore_load_default_account_id(output_account_id);
689
690         EM_DEBUG_FUNC_END("ret[%d]", err);
691         return err;
692 }