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-network.c
29 * @brief This file contains the data structures and interfaces of Network related Functionality provided by
33 #include "email-api.h"
35 #include "email-convert.h"
36 #include "email-api-mailbox.h"
37 #include "email-types.h"
38 #include "email-utilities.h"
39 #include "email-ipc.h"
40 #include "email-storage.h"
45 EXPORT_API int email_send_mail(int mail_id, int *handle)
47 EM_DEBUG_FUNC_BEGIN("mail_id[%d], handle[%p]", mail_id, handle);
49 int err = EMAIL_ERROR_NONE;
50 emstorage_mail_tbl_t* mail_table_data = NULL;
51 email_account_server_t account_server_type;
53 ASNotiData as_noti_data;
56 EM_DEBUG_EXCEPTION("mail_id is not valid");
57 err= EMAIL_ERROR_INVALID_PARAM;
61 if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err) || !mail_table_data) {
62 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
66 if (mail_table_data->account_id <= 0) {
67 EM_DEBUG_EXCEPTION ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", mail_table_data->account_id);
68 emstorage_free_mail(&mail_table_data, 1, NULL);
69 return EMAIL_ERROR_INVALID_PARAM;
72 EM_DEBUG_LOG("mail_table_data->account_id[%d], mail_table_data->mailbox_name[%s]", mail_table_data->account_id, mail_table_data->mailbox_name);
74 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
76 /* check account bind type and branch off */
77 if ( em_get_account_server_type_by_account_id(mail_table_data->account_id, &account_server_type, false, &err) == false ) {
78 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
79 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
83 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
85 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
86 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
87 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
91 /* noti to active sync */
92 as_noti_data.send_mail.handle = as_handle;
93 as_noti_data.send_mail.account_id = mail_table_data->account_id;
94 as_noti_data.send_mail.mail_id = mail_id;
96 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEND_MAIL, &as_noti_data) == false) {
97 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
98 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
106 hAPI = emipc_create_email_api(_EMAIL_API_SEND_MAIL);
109 EM_DEBUG_EXCEPTION ("INVALID PARAM: hAPI NULL ");
110 emstorage_free_mail(&mail_table_data, 1, NULL);
111 return EMAIL_ERROR_NULL_VALUE;
115 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))){
116 EM_DEBUG_EXCEPTION("email_send_mail--Add Param mail_id failed");
117 emstorage_free_mail(&mail_table_data, 1, NULL);
118 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
121 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
122 EM_DEBUG_EXCEPTION("email_send_mail--emipc_execute_proxy_api failed ");
123 emstorage_free_mail(&mail_table_data, 1, NULL);
124 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_CRASH);
127 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
128 if (err == EMAIL_ERROR_NONE) {
130 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
135 emipc_destroy_email_api(hAPI);
136 hAPI = (HIPC_API)NULL;
138 emstorage_free_mail(&mail_table_data, 1, NULL);
140 EM_DEBUG_FUNC_END("err [%d]", err);
144 EXPORT_API int email_send_mail_with_downloading_attachment_of_original_mail(int input_mail_id, int *output_handle)
146 EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_handle[%p]", input_mail_id, output_handle);
148 int err = EMAIL_ERROR_NONE;
149 emstorage_mail_tbl_t* mail_table_data = NULL;
150 email_account_server_t account_server_type;
151 HIPC_API hAPI = NULL;
152 task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL task_parameter;
154 if(input_mail_id <= 0) {
155 EM_DEBUG_EXCEPTION("mail_id is not valid");
156 err= EMAIL_ERROR_INVALID_PARAM;
160 if(!emstorage_get_mail_by_id(input_mail_id, &mail_table_data, true, &err) || !mail_table_data) {
161 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
165 if (mail_table_data->account_id <= 0) {
166 EM_DEBUG_EXCEPTION ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", mail_table_data->account_id);
167 emstorage_free_mail(&mail_table_data, 1, NULL);
168 return EMAIL_ERROR_INVALID_PARAM;
171 EM_DEBUG_LOG("mail_table_data->account_id[%d], mail_table_data->mailbox_name[%s]", mail_table_data->account_id, mail_table_data->mailbox_name);
173 /* check account bind type and branch off */
174 if ( em_get_account_server_type_by_account_id(mail_table_data->account_id, &account_server_type, false, &err) == false ) {
175 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
176 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
180 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
182 ASNotiData as_noti_data;
184 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
186 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
187 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
188 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
192 /* noti to active sync */
193 as_noti_data.send_mail_with_downloading_attachment_of_original_mail.handle = as_handle;
194 as_noti_data.send_mail_with_downloading_attachment_of_original_mail.mail_id = input_mail_id;
196 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEND_MAIL_WITH_DOWNLOADING_OF_ORIGINAL_MAIL, &as_noti_data) == false) {
197 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
198 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
203 *output_handle = as_handle;
206 task_parameter.mail_id = input_mail_id;
208 if((err = emipc_execute_proxy_task(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, &task_parameter)) != EMAIL_ERROR_NONE) {
209 EM_DEBUG_EXCEPTION("execute_proxy_task failed [%d]", err);
215 emipc_destroy_email_api(hAPI);
216 hAPI = (HIPC_API)NULL;
218 emstorage_free_mail(&mail_table_data, 1, NULL);
220 EM_DEBUG_FUNC_END("err [%d]", err);
224 EXPORT_API int email_send_saved(int account_id, int *handle)
226 EM_DEBUG_FUNC_BEGIN("account_id[%d], handle[%p]", account_id, handle);
228 char* pOptionStream = NULL;
229 int err = EMAIL_ERROR_NONE;
231 EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
232 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM);
234 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_SAVED);
236 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
239 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(account_id), sizeof(int))) {
240 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed");
241 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
245 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
246 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
247 EM_SAFE_FREE(pOptionStream);
248 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
251 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
252 emipc_destroy_email_api(hAPI);
255 EM_SAFE_FREE(pOptionStream);
257 EM_DEBUG_FUNC_END("err [%d]", err);
261 EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, int *handle)
263 EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mailbox_id[%d] handle[%p]", input_account_id, input_mailbox_id, handle);
264 int err = EMAIL_ERROR_NONE;
265 /* int total_count = 0; */
267 EM_IF_ACCOUNT_ID_NULL(input_account_id, EMAIL_ERROR_INVALID_PARAM);
269 email_account_server_t account_server_type;
270 HIPC_API hAPI = NULL;
271 ASNotiData as_noti_data;
272 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
274 /* 2010/02/12 ch715.lee : check account bind type and branch off */
275 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
276 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
280 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
282 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
283 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
287 /* noti to active sync */
288 as_noti_data.sync_header.handle = as_handle;
289 as_noti_data.sync_header.account_id = input_account_id;
290 /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
291 as_noti_data.sync_header.mailbox_id = input_mailbox_id;
293 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
294 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
295 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
304 hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
306 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
308 /* input_account_id */
309 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_account_id, sizeof(int))) {
310 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
311 err = EMAIL_ERROR_OUT_OF_MEMORY;
315 /* input_mailbox_id */
316 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
317 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
318 err = EMAIL_ERROR_OUT_OF_MEMORY;
322 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
323 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
324 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
327 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
329 if (err != EMAIL_ERROR_NONE)
333 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
337 emipc_destroy_email_api(hAPI);
340 EM_DEBUG_FUNC_END("err [%d]", err);
345 EXPORT_API int email_sync_header_for_all_account(int *handle)
347 EM_DEBUG_FUNC_BEGIN("handle[%p]", handle);
348 char* mailbox_stream = NULL;
349 int err = EMAIL_ERROR_NONE;
350 HIPC_API hAPI = NULL;
352 ASNotiData as_noti_data;
353 int i, account_count = 0;
354 emstorage_account_tbl_t *account_tbl_array = NULL;
356 int input_account_id = ALL_ACCOUNT;
357 int input_mailbox_id = 0; /* all case */
359 hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
361 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
363 /* input_account_id */
364 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_account_id, sizeof(int))) {
365 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
366 err = EMAIL_ERROR_OUT_OF_MEMORY;
370 /* input_account_id */
371 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
372 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
373 err = EMAIL_ERROR_OUT_OF_MEMORY;
377 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
378 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
379 EM_SAFE_FREE(mailbox_stream);
380 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
383 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
385 if (err != EMAIL_ERROR_NONE)
388 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &return_handle);
390 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
392 /* Get all accounts for sending notification to active sync engine. */
393 if (!emstorage_get_account_list(&account_count, &account_tbl_array , true, false, &as_err)) {
394 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [ %d ] ", as_err);
399 for(i = 0; i < account_count; i++) {
400 if ( account_tbl_array[i].incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
401 /* use returned handle value for a active sync handle */
404 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
405 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
410 /* noti to active sync */
411 as_noti_data.sync_header.handle = return_handle;
412 as_noti_data.sync_header.account_id = account_tbl_array[i].account_id;
413 /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
414 as_noti_data.sync_header.mailbox_id = 0;
416 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
417 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
418 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
425 *handle = return_handle;
429 emipc_destroy_email_api(hAPI);
432 if ( account_tbl_array )
433 emstorage_free_account(&account_tbl_array, account_count, NULL);
435 EM_DEBUG_FUNC_END("err [%d]", err);
439 EXPORT_API int email_download_body(int mail_id, int with_attachment, int *handle)
441 EM_DEBUG_FUNC_BEGIN("mail_id[%d],with_attachment[%d]", mail_id, with_attachment);
442 int err = EMAIL_ERROR_NONE;
443 emstorage_mail_tbl_t* mail_table_data = NULL;
445 email_account_server_t account_server_type;
446 HIPC_API hAPI = NULL;
447 ASNotiData as_noti_data;
448 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
451 EM_DEBUG_EXCEPTION("mail_id is not valid");
452 err= EMAIL_ERROR_INVALID_PARAM;
456 if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err) || !mail_table_data ) {
457 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
461 if (mail_table_data->account_id <= 0) {
462 EM_DEBUG_EXCEPTION("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", mail_table_data->account_id);
466 account_id = mail_table_data->account_id;
468 /* 2010/02/12 ch715.lee : check account bind type and branch off */
469 if ( em_get_account_server_type_by_account_id(account_id, &account_server_type, true, &err) == false ) {
470 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
474 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
476 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
477 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
481 /* noti to active sync */
482 as_noti_data.download_body.handle = as_handle;
483 as_noti_data.download_body.account_id = account_id;
484 as_noti_data.download_body.mail_id = mail_id;
485 as_noti_data.download_body.with_attachment = with_attachment;
487 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, &as_noti_data) == false) {
488 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
489 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
496 hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_BODY);
498 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
501 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
502 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
503 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
506 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
507 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
508 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
511 /* with_attachment */
512 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&with_attachment, sizeof(int))) {
513 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
514 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
517 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
518 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
519 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
522 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
523 if (err != EMAIL_ERROR_NONE)
528 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
529 EM_DEBUG_LOG("RETURN VALUE : %d handle %d", err, *handle);
535 emipc_destroy_email_api(hAPI);
538 if(mail_table_data) {
539 emstorage_free_mail(&mail_table_data, 1, &err);
542 EM_DEBUG_FUNC_END("err [%d]", err);
548 /* API - Downloads the Email Attachment Information [ INTERNAL ] */
550 EXPORT_API int email_download_attachment(int mail_id, int nth, int *handle)
552 EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], handle[%p]", mail_id, nth, handle);
553 char* mailbox_stream = NULL;
554 int err = EMAIL_ERROR_NONE;
555 emstorage_mail_tbl_t* mail_table_data = NULL;
557 email_account_server_t account_server_type;
558 HIPC_API hAPI = NULL;
559 ASNotiData as_noti_data;
560 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
563 EM_DEBUG_EXCEPTION("mail_id is not valid");
564 err= EMAIL_ERROR_INVALID_PARAM;
568 if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err) || !mail_table_data ) {
569 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
573 if (mail_table_data->account_id <= 0) {
574 EM_DEBUG_EXCEPTION("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", mail_table_data->account_id);
578 account_id = mail_table_data->account_id;
580 if ( em_get_account_server_type_by_account_id(account_id, &account_server_type, true, &err) == false ) {
581 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
585 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
587 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
588 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
592 /* noti to active sync */
593 as_noti_data.download_attachment.handle = as_handle;
594 as_noti_data.download_attachment.account_id = account_id;
595 as_noti_data.download_attachment.mail_id = mail_id;
596 as_noti_data.download_attachment.attachment_order = nth;
597 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, &as_noti_data) == false) {
598 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
599 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
606 hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_ATTACHMENT);
608 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
611 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
612 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
613 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
617 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
618 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
619 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
623 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(nth), sizeof(int))) {
624 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
625 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
629 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
630 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
631 EM_SAFE_FREE(mailbox_stream);
632 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
635 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
636 if (err != EMAIL_ERROR_NONE)
640 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
645 emipc_destroy_email_api(hAPI);
648 if(mail_table_data) {
649 emstorage_free_mail(&mail_table_data, 1, &err);
652 EM_DEBUG_FUNC_END("err [%d]", err);
658 EXPORT_API int email_cancel_job(int input_account_id, int input_handle, email_cancelation_type input_cancel_type)
660 EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_handle [%d], input_cancel_type [%d]", input_account_id, input_handle, input_cancel_type);
661 int err = EMAIL_ERROR_NONE;
662 email_account_server_t account_server_type;
663 HIPC_API hAPI = NULL;
664 ASNotiData as_noti_data;
665 emstorage_account_tbl_t *account_list = NULL;
666 int i, account_count = 0;
668 if(input_account_id < 0)
669 return EMAIL_ERROR_INVALID_PARAM;
671 if ( input_account_id == ALL_ACCOUNT ) {
672 /* this means that job is executed with all account */
673 /* Get all accounts for sending notification to active sync engine. */
674 if (!emstorage_get_account_list(&account_count, &account_list , true, false, &err)) {
675 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
679 for(i = 0; i < account_count; i++) {
680 if ( em_get_account_server_type_by_account_id(account_list[i].account_id, &account_server_type, true, &err) == false ) {
681 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
685 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
686 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
687 as_noti_data.cancel_job.account_id = account_list[i].account_id;
688 as_noti_data.cancel_job.handle = input_handle;
689 as_noti_data.cancel_job.cancel_type = input_cancel_type;
692 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
693 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
694 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
700 /* request canceling to stub */
701 hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
704 EM_DEBUG_EXCEPTION ("INVALID PARAM: hAPI NULL ");
705 err = EMAIL_ERROR_NULL_VALUE;
709 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_account_id, sizeof(int))) { /* input_account_id == 0 */
710 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
711 err = EMAIL_ERROR_NULL_VALUE;
715 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_handle, sizeof(int))) {
716 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
717 err = EMAIL_ERROR_NULL_VALUE;
722 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
723 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
724 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
728 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
729 emipc_destroy_email_api(hAPI);
733 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
734 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
738 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
739 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
740 as_noti_data.cancel_job.account_id = input_account_id;
741 as_noti_data.cancel_job.handle = input_handle;
743 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
744 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
745 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
749 hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
751 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
753 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_account_id, sizeof(int))) {
754 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
755 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
758 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_handle, sizeof(int))) {
759 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
760 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
764 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
765 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
766 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
768 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
769 emipc_destroy_email_api(hAPI);
775 emipc_destroy_email_api(hAPI);
778 emstorage_free_account(&account_list, account_count, NULL);
780 EM_DEBUG_FUNC_END("err [%d]", err);
786 EXPORT_API int email_get_pending_job(email_action_t action, int account_id, int mail_id, email_event_status_type_t * status)
788 EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d], status[%p]", action, account_id, mail_id, status);
790 int err = EMAIL_ERROR_NONE;
792 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_NULL_VALUE);
794 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_PENDING_JOB);
796 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
798 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &action, sizeof(int))) {
799 EM_DEBUG_EXCEPTION("emipc_add_parameter action failed ");
800 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
803 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
804 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
805 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
808 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int))) {
809 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
810 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
814 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
815 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed ");
816 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
819 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
822 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), status);
823 EM_DEBUG_LOG("status : %d ", *status);
826 emipc_destroy_email_api(hAPI);
829 EM_DEBUG_FUNC_END("err [%d]", err);
836 EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving)
838 EM_DEBUG_FUNC_BEGIN("on_sending[%p], on_receiving[%p]", on_sending, on_receiving);
839 int err = EMAIL_ERROR_NONE;
841 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_NETWORK_GET_STATUS);
843 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
846 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
847 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
848 emipc_destroy_email_api(hAPI);
850 err = EMAIL_ERROR_IPC_SOCKET_FAILURE ;
851 EM_DEBUG_FUNC_END("err [%d]", err); return err;
855 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), on_sending );
857 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), on_receiving);
859 emipc_destroy_email_api(hAPI);
861 EM_DEBUG_FUNC_END("err [%d]", err);
865 EXPORT_API int email_sync_imap_mailbox_list(int account_id, int *handle)
867 EM_DEBUG_FUNC_BEGIN();
869 int err = EMAIL_ERROR_NONE;
871 if(account_id <= 0) {
872 EM_DEBUG_LOG("invalid parameters");
873 return EMAIL_ERROR_INVALID_PARAM;
876 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_IMAP_MAILBOX_LIST);
879 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
880 EM_DEBUG_LOG("emipc_add_parameter failed ");
881 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
884 if(!emipc_execute_proxy_api(hAPI)) {
885 EM_DEBUG_LOG("ipcProxy_ExecuteAsyncAPI failed");
886 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
889 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
891 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
893 emipc_destroy_email_api(hAPI);
896 EM_DEBUG_FUNC_END("err [%d]", err);
900 EXPORT_API int email_search_mail_on_server(int input_account_id, int input_mailbox_id, email_search_filter_t *input_search_filter_list, int input_search_filter_count, int *output_handle)
902 EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d], input_search_filter_list [%p], input_search_filter_count [%d], output_handle [%p]", input_account_id, input_mailbox_id, input_search_filter_list, input_search_filter_count, output_handle);
904 int err = EMAIL_ERROR_NONE;
905 int return_value = 0;
906 int stream_size_for_search_filter_list = 0;
907 char *stream_for_search_filter_list = NULL;
908 HIPC_API hAPI = NULL;
909 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
910 ASNotiData as_noti_data;
912 EM_IF_NULL_RETURN_VALUE(input_account_id, EMAIL_ERROR_INVALID_PARAM);
913 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
914 EM_IF_NULL_RETURN_VALUE(input_search_filter_list, EMAIL_ERROR_INVALID_PARAM);
916 memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
918 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
919 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
923 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
926 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
927 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
931 /* noti to active sync */
932 as_noti_data.search_mail_on_server.handle = as_handle;
933 as_noti_data.search_mail_on_server.account_id = input_account_id;
934 as_noti_data.search_mail_on_server.mailbox_id = input_mailbox_id;
935 as_noti_data.search_mail_on_server.search_filter_list = input_search_filter_list;
936 as_noti_data.search_mail_on_server.search_filter_count = input_search_filter_count;
938 return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, &as_noti_data);
940 if ( return_value == false ) {
941 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
942 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
947 *output_handle = as_handle;
951 hAPI = emipc_create_email_api(_EMAIL_API_SEARCH_MAIL_ON_SERVER);
953 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
955 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int))) {
956 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
957 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
961 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_mailbox_id, sizeof(int))){
962 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
963 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
967 stream_for_search_filter_list = em_convert_search_filter_to_byte_stream(input_search_filter_list, input_search_filter_count, &stream_size_for_search_filter_list);
969 EM_PROXY_IF_NULL_RETURN_VALUE(stream_for_search_filter_list, hAPI, EMAIL_ERROR_NULL_VALUE);
971 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, stream_for_search_filter_list, stream_size_for_search_filter_list)) {
972 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
973 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
977 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
978 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
979 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
982 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
984 if (err != EMAIL_ERROR_NONE) {
985 EM_DEBUG_EXCEPTION("_EMAIL_API_SEARCH_MAIL_ON_SERVER failed [%d]", err);
990 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle);
995 emipc_destroy_email_api(hAPI);
999 EM_DEBUG_FUNC_END("err [%d]", err);
1003 EXPORT_API int email_clear_result_of_search_mail_on_server(int input_account_id)
1005 EM_DEBUG_FUNC_BEGIN("input_account_id [%d]", input_account_id);
1007 int err = EMAIL_ERROR_NONE;
1008 int return_value = 0;
1009 HIPC_API hAPI = NULL;
1010 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
1011 ASNotiData as_noti_data;
1013 EM_IF_NULL_RETURN_VALUE(input_account_id, EMAIL_ERROR_INVALID_PARAM);
1015 memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
1017 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
1018 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
1022 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
1025 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
1026 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
1030 /* noti to active sync */
1031 as_noti_data.clear_result_of_search_mail_on_server.handle = as_handle;
1032 as_noti_data.clear_result_of_search_mail_on_server.account_id = input_account_id;
1034 return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER, &as_noti_data);
1036 if ( return_value == false ) {
1037 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
1038 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
1043 hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER);
1045 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
1047 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int))) {
1048 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1049 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
1053 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1054 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1055 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
1058 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1060 if (err != EMAIL_ERROR_NONE) {
1061 EM_DEBUG_EXCEPTION("_EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER failed [%d]", err);
1068 emipc_destroy_email_api(hAPI);
1072 EM_DEBUG_FUNC_END("err [%d]", err);