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