4 * Copyright (c) 2012 - 2013 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.
26 * This file contains the data structures and interfaces needed for application,
27 * to interact with email-service.
28 * @file email_api_mailbox.c
29 * @brief This file contains the data structures and interfaces of mailbox related Functionality provided by
33 #include "email-api.h"
35 #include "email-convert.h"
36 #include "email-storage.h"
37 #include "email-core-utils.h"
38 #include "email-utilities.h"
39 #include "email-ipc.h"
42 /* API - Create a mailbox */
44 EXPORT_API int email_add_mailbox(email_mailbox_t* new_mailbox, int on_server, int *handle)
46 EM_DEBUG_FUNC_BEGIN();
49 int err = EMAIL_ERROR_NONE;
50 char* local_mailbox_stream = NULL;
51 email_account_server_t account_server_type;
53 ASNotiData as_noti_data;
55 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
57 EM_IF_NULL_RETURN_VALUE(new_mailbox, EMAIL_ERROR_INVALID_PARAM);
59 /* check account bind type and branch off */
60 if ( em_get_account_server_type_by_account_id(new_mailbox->account_id, &account_server_type, false, &err) == false ) {
61 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
62 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
66 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && on_server) {
69 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
70 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
71 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
75 /* noti to active sync */
76 as_noti_data.add_mailbox.handle = as_handle;
77 as_noti_data.add_mailbox.account_id = new_mailbox->account_id;
78 as_noti_data.add_mailbox.mailbox_alias = new_mailbox->alias;
79 as_noti_data.add_mailbox.mailbox_path = new_mailbox->mailbox_name;
81 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_ADD_MAILBOX, &as_noti_data) == false) {
82 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
83 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
91 hAPI = emipc_create_email_api(_EMAIL_API_ADD_MAILBOX);
93 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
95 local_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
97 EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMAIL_ERROR_NULL_VALUE);
99 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size)) {
100 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
101 EM_SAFE_FREE(local_mailbox_stream);
102 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
105 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int))) {
106 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
107 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
110 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
111 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
112 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
115 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
116 EM_DEBUG_LOG(" >>>>> error VALUE [%d]", err);
119 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
120 EM_DEBUG_LOG(" >>>>> Handle [%d]", *handle);
123 emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), &(new_mailbox->mailbox_id));
124 EM_DEBUG_LOG(" >>>>> new_mailbox->mailbox_id [%d]", new_mailbox->mailbox_id);
126 emipc_destroy_email_api(hAPI);
131 EM_SAFE_FREE(local_mailbox_stream);
133 EM_DEBUG_FUNC_END("err [%d]", err);
137 EXPORT_API int email_rename_mailbox(int input_mailbox_id, char *input_mailbox_name, char *input_mailbox_alias, int input_on_server, int *output_handle)
139 EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_name [%p], input_mailbox_alias [%p], input_on_server [%d], output_handle [%p]", input_mailbox_id, input_mailbox_name, input_mailbox_alias, input_on_server, output_handle);
141 int err = EMAIL_ERROR_NONE;
142 email_account_server_t account_server_type;
143 HIPC_API hAPI = NULL;
144 ASNotiData as_noti_data;
145 emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
147 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
148 EM_IF_NULL_RETURN_VALUE(input_mailbox_name, EMAIL_ERROR_INVALID_PARAM);
149 EM_IF_NULL_RETURN_VALUE(input_mailbox_alias, EMAIL_ERROR_INVALID_PARAM);
151 if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
152 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
156 /* check account bind type and branch off */
157 if ( em_get_account_server_type_by_account_id(mailbox_tbl->account_id, &account_server_type, false, &err) == false ) {
158 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
159 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
163 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_on_server) {
166 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
167 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
168 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
172 /* noti to active sync */
173 as_noti_data.rename_mailbox.handle = as_handle;
174 as_noti_data.rename_mailbox.account_id = mailbox_tbl->account_id;
175 as_noti_data.rename_mailbox.mailbox_id = input_mailbox_id;
176 as_noti_data.rename_mailbox.mailbox_name = input_mailbox_name;
177 as_noti_data.rename_mailbox.mailbox_alias = input_mailbox_alias;
179 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_RENAME_MAILBOX, &as_noti_data) == false) {
180 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
181 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
186 *output_handle = as_handle;
189 hAPI = emipc_create_email_api(_EMAIL_API_RENAME_MAILBOX);
191 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_mailbox_id, sizeof(int))) {
192 EM_DEBUG_EXCEPTION(" emipc_add_parameter for input_mailbox_id failed");
193 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
196 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, input_mailbox_name, EM_SAFE_STRLEN(input_mailbox_name)+1 )) {
197 EM_DEBUG_EXCEPTION(" emipc_add_parameter for input_mailbox_path failed");
198 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
201 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, input_mailbox_alias, EM_SAFE_STRLEN(input_mailbox_alias)+1 )) {
202 EM_DEBUG_EXCEPTION(" emipc_add_parameter for input_mailbox_alias failed");
203 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
206 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_on_server, sizeof(int))) {
207 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
208 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
211 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
212 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
213 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
216 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
218 EM_DEBUG_LOG("error VALUE [%d]", err);
219 emipc_destroy_email_api(hAPI);
223 emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
225 EM_DEBUG_FUNC_END("err [%d]", err);
230 /* API - Delete a mailbox */
232 EXPORT_API int email_delete_mailbox(int input_mailbox_id, int input_on_server, int *output_handle)
234 EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_on_server[%d] output_handle[%p]", input_mailbox_id, input_on_server, output_handle);
236 int err = EMAIL_ERROR_NONE;
237 email_account_server_t account_server_type;
238 emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
239 HIPC_API hAPI = NULL;
240 ASNotiData as_noti_data;
242 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
244 if ( (err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) {
245 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed[%d]", err);
249 /* check account bind type and branch off */
250 if ( em_get_account_server_type_by_account_id(mailbox_tbl->account_id, &account_server_type, false, &err) == false ) {
251 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
252 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
256 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_on_server) {
259 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
260 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
261 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
265 /* noti to active sync */
266 as_noti_data.delete_mailbox.handle = as_handle;
267 as_noti_data.delete_mailbox.account_id = mailbox_tbl->account_id;
268 as_noti_data.delete_mailbox.mailbox_id = input_mailbox_id;
270 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DELETE_MAILBOX, &as_noti_data) == false) {
271 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
272 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
277 *output_handle = as_handle;
280 hAPI = emipc_create_email_api(_EMAIL_API_DELETE_MAILBOX);
282 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
284 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_mailbox_id, sizeof(int))) {
285 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
286 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
289 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_on_server, sizeof(int))) {
290 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
291 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
294 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
295 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
296 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
299 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
300 EM_DEBUG_LOG("error VALUE [%d]", err);
302 if(input_on_server) {
303 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle);
304 EM_DEBUG_LOG("output_handle [%d]", output_handle);
307 emipc_destroy_email_api(hAPI);
312 emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
315 EM_DEBUG_FUNC_END("err [%d]", err);
319 EXPORT_API int email_delete_mailbox_ex(int input_account_id, int *input_mailbox_id_array, int input_mailbox_id_count, int input_on_server, int *output_handle)
321 EM_DEBUG_FUNC_BEGIN("input_account_id [%d] input_mailbox_id_array[%p] input_mailbox_id_count[%d] input_on_server[%d] output_handle[%p]", input_mailbox_id_array, input_mailbox_id_array, input_mailbox_id_count, input_on_server, output_handle);
322 int err = EMAIL_ERROR_NONE;
323 email_account_server_t account_server_type;
324 task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX task_parameter;
326 if(input_account_id == 0 || input_mailbox_id_count <= 0 || input_mailbox_id_array == NULL) {
327 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
328 err = EMAIL_ERROR_INVALID_PARAM;
332 /* check account bind type and branch off */
333 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, false, &err) == false ) {
334 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
335 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
339 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_on_server) {
341 ASNotiData as_noti_data;
343 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
344 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
345 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
349 /* noti to active sync */
350 as_noti_data.delete_mailbox_ex.handle = as_handle;
351 as_noti_data.delete_mailbox_ex.account_id = input_account_id;
352 as_noti_data.delete_mailbox_ex.mailbox_id_array = input_mailbox_id_array;
353 as_noti_data.delete_mailbox_ex.mailbox_id_count = input_mailbox_id_count;
354 as_noti_data.delete_mailbox_ex.on_server = input_on_server;
356 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DELETE_MAILBOX_EX, &as_noti_data) == false) {
357 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
358 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
363 *output_handle = as_handle;
366 task_parameter.account_id = input_account_id;
367 task_parameter.mailbox_id_array = input_mailbox_id_array;
368 task_parameter.mailbox_id_count = input_mailbox_id_count;
369 task_parameter.on_server = input_on_server;
371 if((err = emipc_execute_proxy_task(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX, &task_parameter)) != EMAIL_ERROR_NONE) {
372 EM_DEBUG_EXCEPTION("execute_proxy_task failed [%d]", err);
379 EM_DEBUG_FUNC_END("err [%d]", err);
383 EXPORT_API int email_set_mailbox_type(int input_mailbox_id, email_mailbox_type_e input_mailbox_type)
385 EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_mailbox_type [%d]", input_mailbox_id, input_mailbox_type);
386 int err = EMAIL_ERROR_NONE;
388 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
390 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_MAILBOX_TYPE);
392 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
394 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_mailbox_id, sizeof(int))) {
395 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
396 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
399 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_mailbox_type, sizeof(int))) {
400 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
401 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
404 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
405 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
406 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
409 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
411 EM_DEBUG_LOG("error VALUE [%d]", err);
412 emipc_destroy_email_api(hAPI);
415 EM_DEBUG_FUNC_END("err [%d]", err);
419 EXPORT_API int email_set_local_mailbox(int input_mailbox_id, int input_is_local_mailbox)
421 EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d], input_is_local_mailbox [%d]", input_mailbox_id, input_is_local_mailbox);
422 int err = EMAIL_ERROR_NONE;
424 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
426 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_LOCAL_MAILBOX);
428 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
430 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_mailbox_id, sizeof(int))) {
431 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
432 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
435 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_is_local_mailbox, sizeof(int))) {
436 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
437 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
440 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
441 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
442 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
445 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
447 EM_DEBUG_LOG("error VALUE [%d]", err);
448 emipc_destroy_email_api(hAPI);
451 EM_DEBUG_FUNC_END("err [%d]", err);
455 EXPORT_API int email_get_sync_mailbox_list(int account_id, email_mailbox_t** mailbox_list, int* count)
457 EM_DEBUG_FUNC_BEGIN();
458 int mailbox_count = 0;
459 int err = EMAIL_ERROR_NONE ;
461 emstorage_mailbox_tbl_t* mailbox_tbl_list = NULL;
463 EM_IF_NULL_RETURN_VALUE(mailbox_list, EMAIL_ERROR_INVALID_PARAM);
464 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM);
465 EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
467 if (!emstorage_get_mailbox_list(account_id, 0, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
468 EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err);
473 err = EMAIL_ERROR_NONE;
475 if (mailbox_count > 0) {
476 if (!(*mailbox_list = em_malloc(sizeof(email_mailbox_t) * mailbox_count))) {
477 EM_DEBUG_EXCEPTION("malloc failed...");
478 err= EMAIL_ERROR_OUT_OF_MEMORY;
481 for (i = 0; i < mailbox_count; i++)
482 em_convert_mailbox_tbl_to_mailbox(mailbox_tbl_list + i, (*mailbox_list) + i);
484 *mailbox_list = NULL;
486 *count = mailbox_count;
489 if (mailbox_tbl_list != NULL)
490 emstorage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
491 EM_DEBUG_FUNC_END("err [%d]", err);
496 EXPORT_API int email_get_mailbox_list(int account_id, int mailbox_sync_type, email_mailbox_t** mailbox_list, int* count)
498 EM_DEBUG_FUNC_BEGIN();
500 int mailbox_count = 0;
501 emstorage_mailbox_tbl_t* mailbox_tbl_list = NULL;
502 int err =EMAIL_ERROR_NONE;
505 EM_IF_NULL_RETURN_VALUE(mailbox_list, EMAIL_ERROR_INVALID_PARAM);
506 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM);
507 EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
509 if (!emstorage_get_mailbox_list(account_id, mailbox_sync_type, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
510 EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err);
514 err = EMAIL_ERROR_NONE;
516 if (mailbox_count > 0) {
517 if (!(*mailbox_list = em_malloc(sizeof(email_mailbox_t) * mailbox_count))) {
518 EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
519 err= EMAIL_ERROR_OUT_OF_MEMORY;
523 for (i = 0; i < mailbox_count; i++)
524 em_convert_mailbox_tbl_to_mailbox(mailbox_tbl_list + i, (*mailbox_list) + i);
526 *mailbox_list = NULL;
528 *count = mailbox_count;
531 if (mailbox_tbl_list != NULL)
532 emstorage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
534 EM_DEBUG_FUNC_END("err [%d]", err);
540 EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, email_mailbox_t** mailbox_list, int* count)
542 EM_DEBUG_FUNC_BEGIN();
544 int mailbox_count = 0;
545 emstorage_mailbox_tbl_t* mailbox_tbl_list = NULL;
546 int err =EMAIL_ERROR_NONE;
549 EM_IF_NULL_RETURN_VALUE(mailbox_list, EMAIL_ERROR_INVALID_PARAM);
550 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM);
551 EM_IF_NULL_RETURN_VALUE(count, EMAIL_ERROR_INVALID_PARAM);
553 if (!emstorage_get_mailbox_list_ex(account_id, mailbox_sync_type, with_count, &mailbox_count, &mailbox_tbl_list, true, &err)) {
554 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_list_ex failed [%d]", err);
558 err = EMAIL_ERROR_NONE;
560 if (mailbox_count > 0) {
561 if (!(*mailbox_list = em_malloc(sizeof(email_mailbox_t) * mailbox_count))) {
562 EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
563 err= EMAIL_ERROR_OUT_OF_MEMORY;
567 for (i = 0; i < mailbox_count; i++)
568 em_convert_mailbox_tbl_to_mailbox(mailbox_tbl_list + i, (*mailbox_list) + i);
571 *mailbox_list = NULL;
574 *count = mailbox_count;
577 if (mailbox_tbl_list != NULL)
578 emstorage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
580 EM_DEBUG_FUNC_END("err [%d]", err);
585 /* sowmya.kr, 05-Apr-2010, new MAPI*/
587 EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, email_mailbox_type_e mailbox_type, email_mailbox_t** mailbox)
589 EM_DEBUG_FUNC_BEGIN();
591 int err = EMAIL_ERROR_NONE;
592 email_mailbox_t* curr_mailbox = NULL;
593 emstorage_mailbox_tbl_t* local_mailbox = NULL;
595 EM_IF_NULL_RETURN_VALUE(mailbox, EMAIL_ERROR_INVALID_PARAM);
596 EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM) ;
599 if(mailbox_type < EMAIL_MAILBOX_TYPE_INBOX || mailbox_type > EMAIL_MAILBOX_TYPE_USER_DEFINED)
600 return EMAIL_ERROR_INVALID_PARAM;
601 if (!emstorage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &local_mailbox, true, &err)) {
602 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err);
606 err = EMAIL_ERROR_NONE;
607 curr_mailbox = em_malloc(sizeof(email_mailbox_t));
608 memset(curr_mailbox, 0x00, sizeof(email_mailbox_t));
609 em_convert_mailbox_tbl_to_mailbox(local_mailbox, curr_mailbox);
612 *mailbox = curr_mailbox;
616 emstorage_free_mailbox(&local_mailbox, 1, NULL);
617 EM_DEBUG_FUNC_END("err [%d]", err);
621 EXPORT_API int email_get_mailbox_by_mailbox_id(int input_mailbox_id, email_mailbox_t** output_mailbox)
623 EM_DEBUG_FUNC_BEGIN();
625 int err = EMAIL_ERROR_NONE;
626 email_mailbox_t* curr_mailbox = NULL;
627 emstorage_mailbox_tbl_t* local_mailbox = NULL;
629 EM_IF_NULL_RETURN_VALUE(output_mailbox, EMAIL_ERROR_INVALID_PARAM);
631 if ( (err = emstorage_get_mailbox_by_id(input_mailbox_id, &local_mailbox)) != EMAIL_ERROR_NONE) {
632 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err);
635 curr_mailbox = em_malloc(sizeof(email_mailbox_t));
637 memset(curr_mailbox, 0x00, sizeof(email_mailbox_t));
639 em_convert_mailbox_tbl_to_mailbox(local_mailbox, curr_mailbox);
642 *output_mailbox = curr_mailbox;
644 emstorage_free_mailbox(&local_mailbox, 1, &err);
646 EM_DEBUG_FUNC_END("err [%d]", err);
650 EXPORT_API int email_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size)
652 EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_id[%d], new_slot_size[%d]", account_id, mailbox_id, new_slot_size);
654 int err = EMAIL_ERROR_NONE;
656 if(new_slot_size < 0) {
657 EM_DEBUG_EXCEPTION("new_slot_size should be greater than 0 or should be equal to 0");
658 return EMAIL_ERROR_INVALID_PARAM;
661 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_MAIL_SLOT_SIZE);
663 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
666 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
667 EM_DEBUG_EXCEPTION(" emipc_add_parameter for account_id failed");
668 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
671 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &mailbox_id, sizeof(int))) {
672 EM_DEBUG_EXCEPTION(" emipc_add_parameter for account_id failed");
673 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
676 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &new_slot_size, sizeof(int))) {
677 EM_DEBUG_EXCEPTION(" emipc_add_parameter for new_slot_size failed");
678 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
681 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
682 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
683 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
686 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
687 EM_DEBUG_LOG("email_set_mail_slot_size error VALUE [%d]", err);
690 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
691 EM_DEBUG_LOG("email_set_mail_slot_size handle VALUE [%d]", handle);
693 emipc_destroy_email_api(hAPI);
697 EM_DEBUG_FUNC_END("err [%d]", err);
701 EXPORT_API int email_stamp_sync_time_of_mailbox(int input_mailbox_id)
703 EM_DEBUG_FUNC_BEGIN("input_mailbox_id [%d]", input_mailbox_id);
705 int err = EMAIL_ERROR_NONE;
707 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
709 err = emstorage_stamp_last_sync_time_of_mailbox(input_mailbox_id, 1);
711 EM_DEBUG_FUNC_END("err [%d]", err);
715 EXPORT_API int email_free_mailbox(email_mailbox_t** mailbox_list, int count)
717 EM_DEBUG_FUNC_BEGIN("mailbox_list[%p], count[%d]", mailbox_list, count);
718 int err = EMAIL_ERROR_NONE;
720 if (count <= 0 || !mailbox_list || !*mailbox_list) {
721 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
722 err = EMAIL_ERROR_INVALID_PARAM;
726 email_mailbox_t *p = *mailbox_list;
729 for (i = 0; i < count; i++) {
730 EM_SAFE_FREE(p[i].mailbox_name);
731 EM_SAFE_FREE(p[i].alias);
735 *mailbox_list = NULL;
738 EM_DEBUG_FUNC_END("err [%d]", err);