4 * Copyright (c) 2000 - 2011 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, email_option_t* sending_option, unsigned* handle)
47 EM_DEBUG_FUNC_BEGIN("mail_id[%d], sending_option[%p], handle[%p]", mail_id, sending_option, handle);
49 char* pSendingOption = NULL;
51 int err = EMAIL_ERROR_NONE;
52 emstorage_mail_tbl_t* mail_table_data = NULL;
55 EM_DEBUG_EXCEPTION("mail_id is not valid");
56 err= EMAIL_ERROR_INVALID_PARAM;
60 if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err) || !mail_table_data) {
61 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
65 EM_IF_ACCOUNT_ID_NULL(mail_table_data->account_id, EMAIL_ERROR_INVALID_PARAM);
67 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);
69 email_account_server_t account_server_type;
71 ASNotiData as_noti_data;
72 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
74 /* check account bind type and branch off */
75 if ( em_get_account_server_type_by_account_id(mail_table_data->account_id, &account_server_type, false, &err) == false ) {
76 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
77 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
81 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
83 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
84 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
85 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
89 /* noti to active sync */
90 as_noti_data.send_mail.handle = as_handle;
91 as_noti_data.send_mail.account_id = mail_table_data->account_id;
92 as_noti_data.send_mail.mail_id = mail_id;
94 memcpy(&as_noti_data.send_mail.options, sending_option, sizeof(email_option_t));
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);
108 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
111 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))){
112 EM_DEBUG_EXCEPTION("email_send_mail--Add Param mail_id failed");
113 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
116 /* sending options */
117 pSendingOption = em_convert_option_to_byte_stream(sending_option, &size);
119 if ( NULL == pSendingOption) {
120 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
123 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pSendingOption, size)){
124 EM_DEBUG_EXCEPTION("email_send_mail--Add Param Sending_Option failed ");
125 EM_SAFE_FREE(pSendingOption);
126 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
129 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
130 EM_DEBUG_EXCEPTION("email_send_mail--emipc_execute_proxy_api failed ");
131 EM_SAFE_FREE(pSendingOption);
132 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_CRASH);
135 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
136 if (err == EMAIL_ERROR_NONE) {
138 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
143 emipc_destroy_email_api(hAPI);
144 hAPI = (HIPC_API)NULL;
145 EM_SAFE_FREE(pSendingOption);
147 EM_DEBUG_FUNC_END("err [%d]", err);
151 EXPORT_API int email_send_saved(int account_id, email_option_t* sending_option, unsigned* handle)
153 EM_DEBUG_FUNC_BEGIN("account_id[%d], sending_option[%p], handle[%p]", account_id, sending_option, handle);
155 char* pOptionStream = NULL;
156 int err = EMAIL_ERROR_NONE;
159 EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
160 EM_IF_NULL_RETURN_VALUE(sending_option, EMAIL_ERROR_INVALID_PARAM);
161 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_INVALID_PARAM);
163 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_SAVED);
165 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
168 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(account_id), sizeof(int))) {
169 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed");
170 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
174 pOptionStream = em_convert_option_to_byte_stream(sending_option, &size);
176 EM_PROXY_IF_NULL_RETURN_VALUE(pOptionStream, hAPI, EMAIL_ERROR_NULL_VALUE);
178 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pOptionStream, size)) {
179 EM_DEBUG_EXCEPTION("Add Param sending option failed");
180 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
184 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
185 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
186 EM_SAFE_FREE(pOptionStream);
187 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
190 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
191 emipc_destroy_email_api(hAPI);
194 EM_SAFE_FREE(pOptionStream);
196 EM_DEBUG_FUNC_END("err [%d]", err);
200 EXPORT_API int email_sync_header(int input_account_id, int input_mailbox_id, unsigned* handle)
202 EM_DEBUG_FUNC_BEGIN("input_account_id[%d], input_mailbox_id[%d] handle[%p]", input_account_id, input_mailbox_id, handle);
203 int err = EMAIL_ERROR_NONE;
204 /* int total_count = 0; */
206 EM_IF_ACCOUNT_ID_NULL(input_account_id, EMAIL_ERROR_INVALID_PARAM);
208 email_account_server_t account_server_type;
209 HIPC_API hAPI = NULL;
210 ASNotiData as_noti_data;
211 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
213 /* 2010/02/12 ch715.lee : check account bind type and branch off */
214 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
215 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
219 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
221 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
222 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
226 /* noti to active sync */
227 as_noti_data.sync_header.handle = as_handle;
228 as_noti_data.sync_header.account_id = input_account_id;
229 /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
230 as_noti_data.sync_header.mailbox_id = input_mailbox_id;
232 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
233 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
234 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
243 hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
245 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
247 /* input_account_id */
248 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_account_id, sizeof(int))) {
249 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
250 err = EMAIL_ERROR_OUT_OF_MEMORY;
254 /* input_mailbox_id */
255 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
256 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
257 err = EMAIL_ERROR_OUT_OF_MEMORY;
261 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
262 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
263 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
266 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
268 if (err != EMAIL_ERROR_NONE)
272 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
276 emipc_destroy_email_api(hAPI);
279 EM_DEBUG_FUNC_END("err [%d]", err);
284 EXPORT_API int email_sync_header_for_all_account(unsigned* handle)
286 EM_DEBUG_FUNC_BEGIN("handle[%p]", handle);
287 char* mailbox_stream = NULL;
288 int err = EMAIL_ERROR_NONE;
289 HIPC_API hAPI = NULL;
291 ASNotiData as_noti_data;
292 int i, account_count = 0;
293 emstorage_account_tbl_t *account_tbl_array = NULL;
295 int input_account_id = ALL_ACCOUNT;
296 int input_mailbox_id = 0; /* all case */
298 hAPI = emipc_create_email_api(_EMAIL_API_SYNC_HEADER);
300 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
302 /* input_account_id */
303 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_account_id, sizeof(int))) {
304 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
305 err = EMAIL_ERROR_OUT_OF_MEMORY;
309 /* input_account_id */
310 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
311 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
312 err = EMAIL_ERROR_OUT_OF_MEMORY;
316 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
317 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
318 EM_SAFE_FREE(mailbox_stream);
319 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
322 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
324 if (err != EMAIL_ERROR_NONE)
327 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &return_handle);
329 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
331 /* Get all accounts for sending notification to active sync engine. */
332 if (!emstorage_get_account_list(&account_count, &account_tbl_array , true, false, &as_err)) {
333 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [ %d ] ", as_err);
338 for(i = 0; i < account_count; i++) {
339 if ( account_tbl_array[i].incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
340 /* use returned handle value for a active sync handle */
343 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
344 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
349 /* noti to active sync */
350 as_noti_data.sync_header.handle = return_handle;
351 as_noti_data.sync_header.account_id = account_tbl_array[i].account_id;
352 /* In case that Mailbox is NULL, SYNC ALL MAILBOX */
353 as_noti_data.sync_header.mailbox_id = 0;
355 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SYNC_HEADER, &as_noti_data) == false) {
356 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
357 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
364 *handle = return_handle;
368 emipc_destroy_email_api(hAPI);
371 if ( account_tbl_array )
372 emstorage_free_account(&account_tbl_array, account_count, NULL);
374 EM_DEBUG_FUNC_END("err [%d]", err);
378 EXPORT_API int email_download_body(int mail_id, int with_attachment, unsigned* handle)
380 EM_DEBUG_FUNC_BEGIN("mail_id[%d],with_attachment[%d]", mail_id, with_attachment);
381 int err = EMAIL_ERROR_NONE;
382 emstorage_mail_tbl_t* mail_table_data = NULL;
384 email_account_server_t account_server_type;
385 HIPC_API hAPI = NULL;
386 ASNotiData as_noti_data;
387 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
390 EM_DEBUG_EXCEPTION("mail_id is not valid");
391 err= EMAIL_ERROR_INVALID_PARAM;
395 if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err) || !mail_table_data ) {
396 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
400 EM_IF_ACCOUNT_ID_NULL(mail_table_data->account_id, EMAIL_ERROR_INVALID_PARAM);
401 account_id = mail_table_data->account_id;
403 /* 2010/02/12 ch715.lee : check account bind type and branch off */
404 if ( em_get_account_server_type_by_account_id(account_id, &account_server_type, true, &err) == false ) {
405 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
409 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
411 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
412 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
416 /* noti to active sync */
417 as_noti_data.download_body.handle = as_handle;
418 as_noti_data.download_body.account_id = account_id;
419 as_noti_data.download_body.mail_id = mail_id;
420 as_noti_data.download_body.with_attachment = with_attachment;
422 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_BODY, &as_noti_data) == false) {
423 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
424 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
431 hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_BODY);
433 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
436 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
437 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
438 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
441 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
442 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
443 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
446 /* with_attachment */
447 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&with_attachment, sizeof(int))) {
448 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
449 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
452 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
453 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
454 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
457 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
458 if (err != EMAIL_ERROR_NONE)
463 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
464 EM_DEBUG_LOG("RETURN VALUE : %d handle %d", err, *handle);
470 emipc_destroy_email_api(hAPI);
473 if(mail_table_data) {
474 emstorage_free_mail(&mail_table_data, 1, &err);
477 EM_DEBUG_FUNC_END("err [%d]", err);
483 /* API - Downloads the Email Attachment Information [ INTERNAL ] */
485 EXPORT_API int email_download_attachment(int mail_id, int nth, unsigned* handle)
487 EM_DEBUG_FUNC_BEGIN("mail_id[%d], nth[%d], handle[%p]", mail_id, nth, handle);
488 char* mailbox_stream = NULL;
489 int err = EMAIL_ERROR_NONE;
490 emstorage_mail_tbl_t* mail_table_data = NULL;
492 email_account_server_t account_server_type;
493 HIPC_API hAPI = NULL;
494 ASNotiData as_noti_data;
495 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
498 EM_DEBUG_EXCEPTION("mail_id is not valid");
499 err= EMAIL_ERROR_INVALID_PARAM;
503 if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err) || !mail_table_data ) {
504 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
508 EM_IF_ACCOUNT_ID_NULL(mail_table_data->account_id, EMAIL_ERROR_INVALID_PARAM);
509 account_id = mail_table_data->account_id;
511 if ( em_get_account_server_type_by_account_id(account_id, &account_server_type, true, &err) == false ) {
512 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
516 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
518 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
519 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
523 /* noti to active sync */
524 as_noti_data.download_attachment.handle = as_handle;
525 as_noti_data.download_attachment.account_id = account_id;
526 as_noti_data.download_attachment.mail_id = mail_id;
527 as_noti_data.download_attachment.attachment_order = nth;
528 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_DOWNLOAD_ATTACHMENT, &as_noti_data) == false) {
529 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
530 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
537 hAPI = emipc_create_email_api(_EMAIL_API_DOWNLOAD_ATTACHMENT);
539 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
542 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
543 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
544 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
548 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
549 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
550 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
554 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(nth), sizeof(int))) {
555 EM_DEBUG_EXCEPTION("emipc_add_parameter mail_id failed");
556 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
560 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
561 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
562 EM_SAFE_FREE(mailbox_stream);
563 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
566 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
567 if (err != EMAIL_ERROR_NONE)
571 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
576 emipc_destroy_email_api(hAPI);
579 if(mail_table_data) {
580 emstorage_free_mail(&mail_table_data, 1, &err);
583 EM_DEBUG_FUNC_END("err [%d]", err);
589 EXPORT_API int email_cancel_job(int input_account_id, int input_handle, email_cancelation_type input_cancel_type)
591 EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_handle [%d], input_cancel_type [%d]", input_account_id, input_handle, input_cancel_type);
592 int err = EMAIL_ERROR_NONE;
593 email_account_server_t account_server_type;
594 HIPC_API hAPI = NULL;
595 ASNotiData as_noti_data;
596 emstorage_account_tbl_t *account_list = NULL;
597 int i, account_count = 0;
599 if(input_account_id < 0)
600 return EMAIL_ERROR_INVALID_PARAM;
602 if ( input_account_id == ALL_ACCOUNT ) {
603 /* this means that job is executed with all account */
604 /* Get all accounts for sending notification to active sync engine. */
605 if (!emstorage_get_account_list(&account_count, &account_list , true, false, &err)) {
606 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
610 for(i = 0; i < account_count; i++) {
611 if ( em_get_account_server_type_by_account_id(account_list[i].account_id, &account_server_type, true, &err) == false ) {
612 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
616 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
617 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
618 as_noti_data.cancel_job.account_id = account_list[i].account_id;
619 as_noti_data.cancel_job.handle = input_handle;
620 as_noti_data.cancel_job.cancel_type = input_cancel_type;
623 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
624 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
625 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
631 /* request canceling to stub */
632 hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
634 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
636 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_account_id, sizeof(int))) { /* input_account_id == 0 */
637 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
638 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
641 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_handle, sizeof(int))) {
642 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
643 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
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);
652 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
653 emipc_destroy_email_api(hAPI);
657 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
658 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
662 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
663 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
664 as_noti_data.cancel_job.account_id = input_account_id;
665 as_noti_data.cancel_job.handle = input_handle;
667 if ( em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CANCEL_JOB, &as_noti_data) == false) {
668 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
669 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
673 hAPI = emipc_create_email_api(_EMAIL_API_CANCEL_JOB);
675 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
677 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_account_id, sizeof(int))) {
678 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
679 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
682 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_handle, sizeof(int))) {
683 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
684 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
688 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
689 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
690 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
692 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
693 emipc_destroy_email_api(hAPI);
699 emipc_destroy_email_api(hAPI);
702 emstorage_free_account(&account_list, account_count, NULL);
704 EM_DEBUG_FUNC_END("err [%d]", err);
710 EXPORT_API int email_get_pending_job(email_action_t action, int account_id, int mail_id, email_event_status_type_t * status)
712 EM_DEBUG_FUNC_BEGIN("action[%d], account_id[%d], mail_id[%d], status[%p]", action, account_id, mail_id, status);
714 int err = EMAIL_ERROR_NONE;
716 EM_IF_ACCOUNT_ID_NULL(account_id, EMAIL_ERROR_NULL_VALUE);
718 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_PENDING_JOB);
720 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
722 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &action, sizeof(int))) {
723 EM_DEBUG_EXCEPTION("emipc_add_parameter action failed ");
724 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
727 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
728 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
729 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
732 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int))) {
733 EM_DEBUG_EXCEPTION("emipc_add_parameter account_id failed ");
734 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
738 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
739 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed ");
740 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
743 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
746 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), status);
747 EM_DEBUG_LOG("status : %d ", *status);
750 emipc_destroy_email_api(hAPI);
753 EM_DEBUG_FUNC_END("err [%d]", err);
760 EXPORT_API int email_get_network_status(int* on_sending, int* on_receiving)
762 EM_DEBUG_FUNC_BEGIN("on_sending[%p], on_receiving[%p]", on_sending, on_receiving);
763 int err = EMAIL_ERROR_NONE;
765 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_NETWORK_GET_STATUS);
767 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
770 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
771 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
772 emipc_destroy_email_api(hAPI);
774 err = EMAIL_ERROR_IPC_SOCKET_FAILURE ;
775 EM_DEBUG_FUNC_END("err [%d]", err); return err;
779 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), on_sending );
781 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), on_receiving);
783 emipc_destroy_email_api(hAPI);
785 EM_DEBUG_FUNC_END("err [%d]", err);
789 EXPORT_API int email_sync_imap_mailbox_list(int account_id, unsigned* handle)
791 EM_DEBUG_FUNC_BEGIN();
793 int err = EMAIL_ERROR_NONE;
795 if(account_id <= 0) {
796 EM_DEBUG_LOG("invalid parameters");
797 return EMAIL_ERROR_INVALID_PARAM;
800 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_IMAP_MAILBOX_LIST);
803 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
804 EM_DEBUG_LOG("emipc_add_parameter failed ");
805 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
808 if(!emipc_execute_proxy_api(hAPI)) {
809 EM_DEBUG_LOG("ipcProxy_ExecuteAsyncAPI failed");
810 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
813 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
815 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
817 emipc_destroy_email_api(hAPI);
820 EM_DEBUG_FUNC_END("err [%d]", err);
824 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, unsigned *output_handle)
826 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);
828 int err = EMAIL_ERROR_NONE;
829 int return_value = 0;
830 int stream_size_for_search_filter_list = 0;
831 char *stream_for_search_filter_list = NULL;
832 HIPC_API hAPI = NULL;
833 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
834 ASNotiData as_noti_data;
836 EM_IF_NULL_RETURN_VALUE(input_account_id, EMAIL_ERROR_INVALID_PARAM);
837 EM_IF_NULL_RETURN_VALUE(input_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
838 EM_IF_NULL_RETURN_VALUE(input_search_filter_list, EMAIL_ERROR_INVALID_PARAM);
840 memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
842 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
843 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
847 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
850 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
851 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
855 /* noti to active sync */
856 as_noti_data.search_mail_on_server.handle = as_handle;
857 as_noti_data.search_mail_on_server.account_id = input_account_id;
858 as_noti_data.search_mail_on_server.mailbox_id = input_mailbox_id;
859 as_noti_data.search_mail_on_server.search_filter_list = input_search_filter_list;
860 as_noti_data.search_mail_on_server.search_filter_count = input_search_filter_count;
862 return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_SEARCH_ON_SERVER, &as_noti_data);
864 if ( return_value == false ) {
865 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
866 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
871 *output_handle = as_handle;
875 hAPI = emipc_create_email_api(_EMAIL_API_SEARCH_MAIL_ON_SERVER);
877 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
879 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_account_id, sizeof(int))) {
880 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
881 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
885 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&input_mailbox_id, sizeof(int))){
886 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
887 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
891 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);
893 EM_PROXY_IF_NULL_RETURN_VALUE(stream_for_search_filter_list, hAPI, EMAIL_ERROR_NULL_VALUE);
895 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, stream_for_search_filter_list, stream_size_for_search_filter_list)) {
896 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
897 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
901 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
902 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
903 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
906 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
908 if (err != EMAIL_ERROR_NONE) {
909 EM_DEBUG_EXCEPTION("_EMAIL_API_SEARCH_MAIL_ON_SERVER failed [%d]", err);
914 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle);
919 emipc_destroy_email_api(hAPI);
923 EM_DEBUG_FUNC_END("err [%d]", err);
927 EXPORT_API int email_clear_result_of_search_mail_on_server(int input_account_id)
929 EM_DEBUG_FUNC_BEGIN("input_account_id [%d]", input_account_id);
931 int err = EMAIL_ERROR_NONE;
932 int return_value = 0;
933 HIPC_API hAPI = NULL;
934 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
935 ASNotiData as_noti_data;
936 emstorage_mailbox_tbl_t* mailbox = NULL;
939 EM_IF_NULL_RETURN_VALUE(input_account_id, EMAIL_ERROR_INVALID_PARAM);
941 memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
943 if ( em_get_account_server_type_by_account_id(input_account_id, &account_server_type, true, &err) == false ) {
944 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
948 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC ) {
951 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
952 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
956 /* noti to active sync */
957 as_noti_data.clear_result_of_search_mail_on_server.handle = as_handle;
958 as_noti_data.clear_result_of_search_mail_on_server.account_id = input_account_id;
960 return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_CLEAR_RESULT_OF_SEARCH_ON_SERVER, &as_noti_data);
962 if ( return_value == false ) {
963 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
964 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
969 if (!emstorage_get_mailbox_by_mailbox_type(input_account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &mailbox, true, &err) || !mailbox) {
970 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err);
973 mailbox_id = mailbox->mailbox_id;
975 hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER);
977 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
979 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (void*)&mailbox_id, sizeof(int))) {
980 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
981 err = EMAIL_ERROR_IPC_PROTOCOL_FAILURE;
985 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
986 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
987 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
990 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
992 if (err != EMAIL_ERROR_NONE) {
993 EM_DEBUG_EXCEPTION("_EMAIL_API_CLEAR_RESULT_OF_SEARCH_MAIL_ON_SERVER failed [%d]", err);
1000 emipc_destroy_email_api(hAPI);
1005 emstorage_free_mailbox(&mailbox, 1, &err);
1007 EM_DEBUG_FUNC_END("err [%d]", err);