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-mail.c
29 * @brief This file contains the data structures and interfaces of Message related Functionality provided by
36 #include "email-api.h"
37 #include "email-ipc.h"
38 #include "email-convert.h"
39 #include "email-core-utils.h"
40 #include "email-core-mail.h"
41 #include "email-core-smtp.h"
42 #include "email-storage.h"
43 #include "email-utilities.h"
46 #define DIR_SEPERATOR_CH '/'
50 #define MAX_SEARCH_LEN 1000
52 EXPORT_API int email_add_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas)
54 EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_request [%p], input_from_eas [%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas);
56 EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
57 EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id, EMAIL_ERROR_INVALID_PARAM);
58 EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_id, EMAIL_ERROR_INVALID_PARAM);
60 if(input_attachment_count > 0 && !input_attachment_data_list) {
61 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
62 return EMAIL_ERROR_INVALID_PARAM;
65 int err = EMAIL_ERROR_NONE;
67 char *mail_data_stream = NULL;
68 char *attachment_data_list_stream = NULL;
69 char *meeting_request_stream = NULL;
72 if(input_from_eas == 0) { /* native emails */
73 hAPI = emipc_create_email_api(_EMAIL_API_ADD_MAIL);
76 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
77 err = EMAIL_ERROR_NULL_VALUE;
81 /* email_mail_data_t */
82 mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, &size);
84 if(!mail_data_stream) {
85 EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
86 err = EMAIL_ERROR_NULL_VALUE;
89 emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size);
91 /* email_attachment_data_t */
92 attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
94 if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
95 EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
96 err = EMAIL_ERROR_OUT_OF_MEMORY;
101 /* email_meeting_request_t */
102 if ( input_mail_data->meeting_request_status != EMAIL_MAIL_TYPE_NORMAL ) {
103 meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
105 if(!meeting_request_stream) {
106 EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
107 err = EMAIL_ERROR_NULL_VALUE;
111 emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size);
115 emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int));
118 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
119 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
120 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
124 /* get result from service */
125 err = *((int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 0));
126 if(err == EMAIL_ERROR_NONE) {
128 input_mail_data->mail_id = *((int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 1));
129 /* result thread_id */
130 input_mail_data->thread_id = *((int*)emipc_get_nth_parameter_data(hAPI, ePARAMETER_OUT, 2));
133 else { /* take care of mails from eas */
134 err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas);
135 if(err != EMAIL_ERROR_NONE) {
136 EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err);
143 emipc_destroy_email_api(hAPI);
145 EM_DEBUG_FUNC_END("err [%d]", err);
150 EXPORT_API int email_add_read_receipt(int input_read_mail_id, int *output_receipt_mail_id)
152 EM_DEBUG_FUNC_BEGIN("input_read_mail_id [%d], output_receipt_mail_id [%p]", input_read_mail_id, output_receipt_mail_id);
154 EM_IF_NULL_RETURN_VALUE(output_receipt_mail_id, EMAIL_ERROR_INVALID_PARAM);
156 int err = EMAIL_ERROR_NONE;
157 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_READ_RECEIPT);
159 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
161 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_read_mail_id, sizeof(int))) {
162 EM_DEBUG_EXCEPTION("Add Param mail body Fail");
163 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
167 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
168 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
169 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
172 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
174 EM_DEBUG_LOG("err [%d]", err);
176 if(err == EMAIL_ERROR_NONE) {
177 /* Get receipt mail id */
178 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_receipt_mail_id);
179 EM_DEBUG_LOG("output_receipt_mail_id [%d]", *output_receipt_mail_id);
182 emipc_destroy_email_api(hAPI);
186 EM_DEBUG_FUNC_END("err [%d]", err);
192 int email_create_db_full()
194 int mailbox_index, mail_index, mailbox_count, mail_slot_size;
195 emstorage_mail_tbl_t mail_table_data = {0};
196 email_mailbox_t *mailbox_list = NULL;
197 int err = EMAIL_ERROR_NONE;
199 if ( (err = email_open_db()) != EMAIL_ERROR_NONE) {
200 EM_DEBUG_EXCEPTION("email_open_db failed [%d]", err);
204 mail_table_data.subject = (char*) em_malloc(50);
205 mail_table_data.full_address_from = strdup("<dummy_from@nowhere.com>");
206 mail_table_data.full_address_to = strdup("<dummy_to@nowhere.com>");
207 mail_table_data.account_id =1;
209 if( (err = email_get_mailbox_list_ex(1, -1, 0, &mailbox_list, &mailbox_count)) < EMAIL_ERROR_NONE) {
210 EM_DEBUG_EXCEPTION("email_get_mailbox_list_ex failed [%d]", err);
214 for(mailbox_index = 0; mailbox_index < mailbox_count; mailbox_index++) {
215 mail_slot_size= mailbox_list[mailbox_index].mail_slot_size;
216 for(mail_index = 0; mail_index < mail_slot_size; mail_index++) {
217 sprintf(mail_table_data.subject, "Subject #%d",mail_index);
218 mail_table_data.mailbox_id = mailbox_list[mailbox_index].mailbox_id;
219 mail_table_data.mailbox_type = mailbox_list[mailbox_index].mailbox_type;
220 if( !emstorage_add_mail(&mail_table_data, 1, true, &err)) {
221 EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]",err);
229 if ( (err = email_close_db()) != EMAIL_ERROR_NONE) {
230 EM_DEBUG_EXCEPTION("email_close_db failed [%d]", err);
234 email_free_mailbox(&mailbox_list, mailbox_count);
236 EM_SAFE_FREE(mail_table_data.subject);
237 EM_SAFE_FREE(mail_table_data.full_address_from);
238 EM_SAFE_FREE(mail_table_data.full_address_to);
243 EXPORT_API int email_update_mail(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data_list, int input_attachment_count, email_meeting_request_t* input_meeting_request, int input_from_eas)
245 EM_DEBUG_FUNC_BEGIN("input_mail_data[%p], input_attachment_data_list[%p], input_attachment_count [%d], input_meeting_request [%p], input_from_eas [%d]", input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas);
247 EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
248 EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id, EMAIL_ERROR_INVALID_PARAM);
250 if(input_attachment_count > 0 && !input_attachment_data_list) {
251 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
252 return EMAIL_ERROR_INVALID_PARAM;
255 int err = EMAIL_ERROR_NONE;
257 char *mail_data_stream = NULL;
258 char *attachment_data_list_stream = NULL;
259 char *meeting_request_stream = NULL;
261 HIPC_API hAPI = NULL;
263 if(input_from_eas == 0) {
264 hAPI = emipc_create_email_api(_EMAIL_API_UPDATE_MAIL);
267 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
268 err = EMAIL_ERROR_NULL_VALUE;
272 /* email_mail_data_t */
273 mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, &size);
275 if(!mail_data_stream) {
276 EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
277 err = EMAIL_ERROR_NULL_VALUE;
281 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
282 EM_DEBUG_EXCEPTION("emipc_add_parameter for head failed");
283 err = EMAIL_ERROR_OUT_OF_MEMORY;
287 /* email_attachment_data_t */
288 attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
290 if(!emipc_add_dynamic_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
291 EM_DEBUG_EXCEPTION("emipc_add_dynamic_parameter failed");
292 err = EMAIL_ERROR_OUT_OF_MEMORY;
296 /* email_meeting_request_t */
297 if ( input_mail_data->meeting_request_status != EMAIL_MAIL_TYPE_NORMAL ) {
298 meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
300 if(!meeting_request_stream) {
301 EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
302 err = EMAIL_ERROR_NULL_VALUE;
306 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
307 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
308 err = EMAIL_ERROR_OUT_OF_MEMORY;
314 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int))) {
315 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
316 err = EMAIL_ERROR_OUT_OF_MEMORY;
321 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
322 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
323 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
327 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
329 if(err == EMAIL_ERROR_NONE) {
330 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &input_mail_data->mail_id);
331 emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), &input_mail_data->thread_id);
335 if( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMAIL_ERROR_NONE) {
336 EM_DEBUG_EXCEPTION("emcore_update_mail failed [%d]", err);
343 emipc_destroy_email_api(hAPI);
345 EM_SAFE_FREE(mail_data_stream);
347 EM_DEBUG_FUNC_END("err [%d]", err);
352 EXPORT_API int email_clear_mail_data()
354 EM_DEBUG_FUNC_BEGIN();
355 int err = EMAIL_ERROR_NONE;
357 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_DATA);
359 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
361 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
362 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api Fail");
363 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_IPC_SOCKET_FAILURE);
365 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
368 emipc_destroy_email_api(hAPI);
370 EM_DEBUG_FUNC_END("err [%d]", err);
375 EXPORT_API int email_count_mail(email_list_filter_t *input_filter_list, int input_filter_count, int *output_total_mail_count, int *output_unseen_mail_count)
377 EM_DEBUG_FUNC_BEGIN("input_filter_list[%p], input_filter_count [%d], output_total_mail_count[%p], output_unseen_mail_count[%p]", input_filter_list, input_filter_count, output_total_mail_count, output_unseen_mail_count);
381 int err = EMAIL_ERROR_NONE;
382 char *conditional_clause_string = NULL;
384 EM_IF_NULL_RETURN_VALUE(input_filter_list, EMAIL_ERROR_INVALID_PARAM);
385 EM_IF_NULL_RETURN_VALUE(input_filter_count, EMAIL_ERROR_INVALID_PARAM);
386 EM_IF_NULL_RETURN_VALUE(output_total_mail_count, EMAIL_ERROR_INVALID_PARAM);
387 EM_IF_NULL_RETURN_VALUE(output_unseen_mail_count, EMAIL_ERROR_INVALID_PARAM);
389 if( (err = emstorage_write_conditional_clause_for_getting_mail_list(input_filter_list, input_filter_count, NULL, 0, -1, -1, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
390 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
394 if ((err = emstorage_query_mail_count(conditional_clause_string, true, &total_count, &unread)) != EMAIL_ERROR_NONE) {
395 EM_DEBUG_EXCEPTION("emstorage_query_mail_count failed [%d]", err);
399 *output_total_mail_count = total_count;
400 *output_unseen_mail_count = unread;
404 EM_DEBUG_FUNC_END("err [%d]", err);
409 EXPORT_API int email_delete_mail(int input_mailbox_id, int *input_mail_ids, int input_num, int input_from_server)
411 EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_mail_ids[%p], input_num[%d], input_from_server[%d]", input_mailbox_id, input_mail_ids, input_num, input_from_server);
413 int err = EMAIL_ERROR_NONE;
414 HIPC_API hAPI = NULL;
416 EM_IF_NULL_RETURN_VALUE(input_mail_ids, EMAIL_ERROR_INVALID_PARAM);
418 if (input_mailbox_id <= 0) {
419 EM_DEBUG_EXCEPTION("input_mailbox_id = %d", input_mailbox_id);
420 err = EMAIL_ERROR_INVALID_PARAM;
424 if (input_num <= 0) {
425 EM_DEBUG_EXCEPTION("input_num = %d", input_num);
426 err = EMAIL_ERROR_INVALID_PARAM;
430 hAPI = emipc_create_email_api(_EMAIL_API_DELETE_MAIL);
433 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
434 err = EMAIL_ERROR_NULL_VALUE;
439 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
440 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
441 err = EMAIL_ERROR_OUT_OF_MEMORY;
445 /* Number of mail_ids */
446 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_num, sizeof(int))) {
447 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
448 err = EMAIL_ERROR_OUT_OF_MEMORY;
452 /* set of mail_ids */
453 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)input_mail_ids, input_num * sizeof(int))) {
454 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
455 err = EMAIL_ERROR_OUT_OF_MEMORY;
460 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_server, sizeof(int))) {
461 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
462 err = EMAIL_ERROR_OUT_OF_MEMORY;
466 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
467 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
468 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
472 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
476 emipc_destroy_email_api(hAPI);
478 EM_DEBUG_FUNC_END("err [%d]", err);
483 EXPORT_API int email_delete_all_mails_in_mailbox(int input_mailbox_id, int input_from_server)
485 EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_from_server[%d]", input_mailbox_id, input_from_server);
487 int err = EMAIL_ERROR_NONE;
488 HIPC_API hAPI = NULL;
490 if(input_mailbox_id <= 0) {
491 EM_DEBUG_EXCEPTION("input_mailbox_id = %d", input_mailbox_id);
492 err = EMAIL_ERROR_INVALID_PARAM;
496 hAPI = emipc_create_email_api(_EMAIL_API_DELETE_ALL_MAIL);
499 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
500 err = EMAIL_ERROR_NULL_VALUE;
504 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
505 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
506 err = EMAIL_ERROR_OUT_OF_MEMORY;
510 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_server, sizeof(int))){
511 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
512 err = EMAIL_ERROR_OUT_OF_MEMORY;
516 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
517 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
518 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
522 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int),&err );
527 emipc_destroy_email_api(hAPI);
529 EM_DEBUG_FUNC_END("err [%d]", err);
535 EXPORT_API int email_add_attachment(int mail_id, email_attachment_data_t* attachment)
537 EM_DEBUG_FUNC_BEGIN("mail_id[%d], attachment[%p]", mail_id, attachment);
538 int err = EMAIL_ERROR_NONE;
539 char *attchment_stream = NULL;
541 HIPC_API hAPI = NULL;
543 EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
544 EM_IF_NULL_RETURN_VALUE(attachment, EMAIL_ERROR_INVALID_PARAM);
546 hAPI = emipc_create_email_api(_EMAIL_API_ADD_ATTACHMENT);
549 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
550 err = EMAIL_ERROR_NULL_VALUE;
555 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
556 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
557 err = EMAIL_ERROR_OUT_OF_MEMORY;
562 attchment_stream = em_convert_attachment_data_to_byte_stream(attachment, 1, &size);
564 if(!attchment_stream) {
565 EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
566 err = EMAIL_ERROR_NULL_VALUE;
570 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, attchment_stream, size)){
571 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
572 err = EMAIL_ERROR_OUT_OF_MEMORY;
577 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
578 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
579 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
583 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
585 if(EMAIL_ERROR_NONE == err) {
586 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &attachment->attachment_id);
590 EM_SAFE_FREE(attchment_stream);
593 emipc_destroy_email_api(hAPI);
595 EM_DEBUG_FUNC_END("err [%d]", err);
600 EXPORT_API int email_delete_attachment(int attachment_id)
602 EM_DEBUG_FUNC_BEGIN("attachment_id[%d]", attachment_id);
603 int err = EMAIL_ERROR_NONE;
604 HIPC_API hAPI = NULL;
606 EM_IF_NULL_RETURN_VALUE(attachment_id, EMAIL_ERROR_INVALID_PARAM);
608 hAPI = emipc_create_email_api(_EMAIL_API_DELETE_ATTACHMENT);
611 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
612 err = EMAIL_ERROR_NULL_VALUE;
616 /* attachment_index */
617 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&attachment_id, sizeof(int))) {
618 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
619 err = EMAIL_ERROR_OUT_OF_MEMORY;
624 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
625 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
626 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
630 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
634 emipc_destroy_email_api(hAPI);
639 /* -----------------------------------------------------------
641 -----------------------------------------------------------*/
643 EXPORT_API int email_query_mails(char *conditional_clause_string, email_mail_data_t** mail_list, int *result_count)
645 EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
647 int err = EMAIL_ERROR_NONE;
648 emstorage_mail_tbl_t *result_mail_tbl;
650 EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
651 EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMAIL_ERROR_INVALID_PARAM);
653 if (!emstorage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, result_count, &err)) {
654 EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err);
659 if(!em_convert_mail_tbl_to_mail_data(result_mail_tbl, *result_count, mail_list, &err)) {
660 EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
665 if(result_mail_tbl && !emstorage_free_mail(&result_mail_tbl, *result_count, &err))
666 EM_DEBUG_EXCEPTION("emstorage_free_mail failed [%d]", err);
668 EM_DEBUG_FUNC_END("err [%d]", err);
672 EXPORT_API int email_query_mail_list(char *input_conditional_clause_string, email_mail_list_item_t** output_mail_list, int *output_result_count)
674 EM_DEBUG_FUNC_BEGIN("input_conditional_clause_string [%s], output_mail_list [%p], output_result_count [%p]", input_conditional_clause_string, output_mail_list, output_result_count);
676 int err = EMAIL_ERROR_NONE;
678 EM_IF_NULL_RETURN_VALUE(input_conditional_clause_string, EMAIL_ERROR_INVALID_PARAM);
679 EM_IF_NULL_RETURN_VALUE(output_result_count, EMAIL_ERROR_INVALID_PARAM);
681 if (!emstorage_query_mail_list(input_conditional_clause_string, true, output_mail_list, output_result_count, &err)) {
682 EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err);
687 EM_DEBUG_FUNC_END("err [%d]", err);
692 /* -----------------------------------------------------------
694 -----------------------------------------------------------*/
695 EXPORT_API int email_get_attachment_data(int attachment_id, email_attachment_data_t** attachment)
697 EM_DEBUG_FUNC_BEGIN("attachment_id[%d], attachment[%p]", attachment_id, attachment);
699 int err = EMAIL_ERROR_NONE;
701 int attachment_count = 0;
702 char* attchment_stream = NULL;
703 email_attachment_data_t* attachment_data = NULL;
705 EM_IF_NULL_RETURN_VALUE(attachment_id, EMAIL_ERROR_INVALID_PARAM);
706 EM_IF_NULL_RETURN_VALUE(attachment, EMAIL_ERROR_INVALID_PARAM);
709 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_ATTACHMENT);
711 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
714 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&attachment_id, sizeof(int))) {
715 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
716 err = EMAIL_ERROR_OUT_OF_MEMORY;
721 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
722 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
723 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
727 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
729 if(EMAIL_ERROR_NONE == err) {
730 nSize = emipc_get_parameter_length(hAPI, ePARAMETER_OUT, 1);
732 attchment_stream = (char*)em_malloc(nSize+1);
734 if(!attchment_stream) {
735 EM_DEBUG_EXCEPTION("em_malloc failed");
736 err = EMAIL_ERROR_OUT_OF_MEMORY;
740 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, nSize, attchment_stream);
741 em_convert_byte_stream_to_attachment_data(attchment_stream, nSize, &attachment_data, &attachment_count);
744 if(!attachment_data) {
745 EM_DEBUG_EXCEPTION("EMAIL_ERROR_NULL_VALUE");
746 err = EMAIL_ERROR_NULL_VALUE;
750 *attachment = attachment_data;
754 EM_SAFE_FREE(attchment_stream);
757 emipc_destroy_email_api(hAPI);
759 EM_DEBUG_FUNC_END("err [%d]", err);
764 EXPORT_API int email_get_attachment_data_list(int input_mail_id, email_attachment_data_t **output_attachment_data, int *output_attachment_count)
766 EM_DEBUG_FUNC_BEGIN("input_mail_id[%d], output_attachment_data[%p], output_attachment_count[%p]", input_mail_id, output_attachment_data, output_attachment_count);
767 int err = EMAIL_ERROR_NONE;
769 if((err = emcore_get_attachment_data_list(input_mail_id, output_attachment_data, output_attachment_count)) != EMAIL_ERROR_NONE) {
770 EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err);
773 EM_DEBUG_FUNC_END("err [%d]", err);
777 EXPORT_API int email_free_attachment_data(email_attachment_data_t **attachment_data_list, int attachment_data_count)
779 EM_DEBUG_FUNC_BEGIN("attachment_data_list[%p], attachment_data_count[%d]", attachment_data_list, attachment_data_count);
781 int err = EMAIL_ERROR_NONE;
783 emcore_free_attachment_data(attachment_data_list, attachment_data_count, &err);
785 EM_DEBUG_FUNC_END("err [%d]", err);
789 EXPORT_API int email_get_mail_list_ex(email_list_filter_t *input_filter_list, int input_filter_count, email_list_sorting_rule_t *input_sorting_rule_list, int input_sorting_rule_count, int input_start_index, int input_limit_count, email_mail_list_item_t** output_mail_list, int *output_result_count)
791 EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d], input_sorting_rule_list[%p], input_sorting_rule_count [%d], input_start_index [%d], input_limit_count [%d], output_mail_list [%p], output_result_count [%p]", input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, output_mail_list, output_result_count);
793 int err = EMAIL_ERROR_NONE;
794 char *conditional_clause_string = NULL;
796 EM_IF_NULL_RETURN_VALUE(output_mail_list, EMAIL_ERROR_INVALID_PARAM);
797 EM_IF_NULL_RETURN_VALUE(output_result_count, EMAIL_ERROR_INVALID_PARAM);
799 if( (err = emstorage_write_conditional_clause_for_getting_mail_list(input_filter_list, input_filter_count, input_sorting_rule_list, input_sorting_rule_count, input_start_index, input_limit_count, &conditional_clause_string)) != EMAIL_ERROR_NONE) {
800 EM_DEBUG_EXCEPTION("emstorage_write_conditional_clause_for_getting_mail_list failed[%d]", err);
804 EM_DEBUG_LOG("conditional_clause_string[%s].", conditional_clause_string);
806 if(!emstorage_query_mail_list(conditional_clause_string, true, output_mail_list, output_result_count, &err)) {
807 EM_DEBUG_EXCEPTION("emstorage_query_mail_list [%d]", err);
812 EM_SAFE_FREE(conditional_clause_string);
814 EM_DEBUG_FUNC_END("err [%d]", err);
818 EXPORT_API int email_free_list_filter(email_list_filter_t **input_filter_list, int input_filter_count)
820 EM_DEBUG_FUNC_BEGIN("input_filter_list [%p], input_filter_count[%d]", input_filter_list, input_filter_count);
821 int err = EMAIL_ERROR_NONE;
823 EM_IF_NULL_RETURN_VALUE(input_filter_list, EMAIL_ERROR_INVALID_PARAM);
825 err = emstorage_free_list_filter(input_filter_list, input_filter_count);
827 EM_DEBUG_FUNC_END("err [%d]", err);
831 EXPORT_API int email_get_mails(int account_id , int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_mail_data_t** mail_list, int* result_count)
833 EM_DEBUG_FUNC_BEGIN();
835 int err = EMAIL_ERROR_NONE;
836 emstorage_mail_tbl_t *mail_tbl_list = NULL;
837 EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
839 if( account_id < ALL_ACCOUNT) {
840 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
841 err = EMAIL_ERROR_INVALID_PARAM ;
845 if (!emstorage_get_mails(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, sorting, true, &mail_tbl_list, result_count, &err)) {
846 EM_DEBUG_EXCEPTION("emstorage_get_mails failed [%d]", err);
851 if(!em_convert_mail_tbl_to_mail_data(mail_tbl_list, *result_count, mail_list, &err)) {
852 EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
857 if(mail_tbl_list && !emstorage_free_mail(&mail_tbl_list, *result_count, &err))
858 EM_DEBUG_EXCEPTION("emstorage_free_mail failed [%d]", err);
860 EM_DEBUG_FUNC_END("err [%d]", err);
864 EXPORT_API int email_get_mail_list(int account_id , int mailbox_id, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, email_mail_list_item_t** mail_list, int* result_count)
866 EM_DEBUG_FUNC_BEGIN();
868 int err = EMAIL_ERROR_NONE;
870 EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
872 if( account_id < ALL_ACCOUNT) {
873 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
874 return EMAIL_ERROR_INVALID_PARAM;
877 if (!emstorage_get_mail_list(account_id, mailbox_id, NULL, thread_id, start_index, limit_count, 0, NULL, sorting, true, mail_list, result_count, &err)) {
878 EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err);
884 EM_DEBUG_FUNC_END("err [%d]", err);
888 EXPORT_API int email_get_mail_by_address(int account_id , int mailbox_id, email_email_address_list_t* addr_list,
889 int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, email_mail_list_item_t** mail_list, int* result_count)
891 EM_DEBUG_FUNC_BEGIN();
892 int err = EMAIL_ERROR_NONE;
894 email_mail_list_item_t* mail_list_item = NULL;
896 EM_IF_NULL_RETURN_VALUE(mail_list, EMAIL_ERROR_INVALID_PARAM);
897 EM_IF_NULL_RETURN_VALUE(result_count, EMAIL_ERROR_INVALID_PARAM);
899 if( account_id < ALL_ACCOUNT) {
900 EM_DEBUG_EXCEPTION("Invalid account id param");
901 err = EMAIL_ERROR_INVALID_PARAM ;
905 if (!emstorage_get_mail_list(account_id, mailbox_id, addr_list, EMAIL_LIST_TYPE_NORMAL, start_index, limit_count, search_type, search_value, sorting, true, &mail_list_item, result_count, &err)) {
906 EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err);
911 *mail_list = mail_list_item;
914 EM_DEBUG_FUNC_END("err [%d]", err);
918 EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, email_mail_data_t** thread_info)
920 EM_DEBUG_FUNC_BEGIN();
921 int err = EMAIL_ERROR_NONE;
922 emstorage_mail_tbl_t *mail_table_data = NULL;
924 EM_IF_NULL_RETURN_VALUE(thread_info, EMAIL_ERROR_INVALID_PARAM);
926 if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
927 EM_DEBUG_EXCEPTION("emstorage_get_thread_information failed [%d]", err);
931 if(!em_convert_mail_tbl_to_mail_data(mail_table_data, 1, thread_info, &err)) {
932 EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
938 if(mail_table_data && !emstorage_free_mail(&mail_table_data, 1, &err))
939 EM_DEBUG_EXCEPTION("emstorage_free_mail failed [%d]", err);
941 EM_DEBUG_FUNC_END("err [%d]", err);
945 EXPORT_API int email_get_thread_information_ex(int thread_id, email_mail_list_item_t** thread_info)
947 EM_DEBUG_FUNC_BEGIN();
948 int err = EMAIL_ERROR_NONE;
949 emstorage_mail_tbl_t *mail_table_data = NULL;
950 email_mail_list_item_t *temp_thread_info = NULL;
952 EM_IF_NULL_RETURN_VALUE(thread_info, EMAIL_ERROR_INVALID_PARAM);
954 if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
955 EM_DEBUG_EXCEPTION("emstorage_get_thread_information -- failed [%d]", err);
959 temp_thread_info = em_malloc(sizeof(email_mail_list_item_t));
961 if(!temp_thread_info) {
962 EM_DEBUG_EXCEPTION("em_malloc failed");
963 err = EMAIL_ERROR_OUT_OF_MEMORY;
967 EM_SAFE_STRNCPY(temp_thread_info->from , mail_table_data->full_address_from, STRING_LENGTH_FOR_DISPLAY);
968 EM_SAFE_STRNCPY(temp_thread_info->from_email_address , mail_table_data->email_address_sender, MAX_EMAIL_ADDRESS_LENGTH);
969 EM_SAFE_STRNCPY(temp_thread_info->recipients , mail_table_data->email_address_recipient, STRING_LENGTH_FOR_DISPLAY);
970 EM_SAFE_STRNCPY(temp_thread_info->subject , mail_table_data->subject, STRING_LENGTH_FOR_DISPLAY);
971 EM_SAFE_STRNCPY(temp_thread_info->previewBodyText , mail_table_data->preview_text, MAX_PREVIEW_TEXT_LENGTH);
972 temp_thread_info->mail_id = mail_table_data->mail_id;
973 temp_thread_info->mailbox_id = mail_table_data->mailbox_id;
974 temp_thread_info->account_id = mail_table_data->account_id;
975 temp_thread_info->date_time = mail_table_data->date_time;
976 temp_thread_info->is_text_downloaded = mail_table_data->body_download_status;
977 temp_thread_info->flags_seen_field = mail_table_data->flags_seen_field;
978 temp_thread_info->priority = mail_table_data->priority;
979 temp_thread_info->save_status = mail_table_data->save_status;
980 temp_thread_info->is_locked = mail_table_data->lock_status;
981 temp_thread_info->is_report_mail = mail_table_data->report_status;
982 temp_thread_info->has_attachment = mail_table_data->attachment_count;
983 temp_thread_info->has_drm_attachment = mail_table_data->DRM_status;
984 temp_thread_info->thread_id = mail_table_data->thread_id;
985 temp_thread_info->thread_item_count = mail_table_data->thread_item_count;
986 temp_thread_info->is_meeting_request = mail_table_data->meeting_request_status;
988 *thread_info = temp_thread_info;
993 emstorage_free_mail(&mail_table_data, 1, NULL);
995 EM_DEBUG_FUNC_END("err [%d]", err);
999 EXPORT_API int email_get_mail_data(int input_mail_id, email_mail_data_t **output_mail_data)
1001 EM_DEBUG_FUNC_BEGIN();
1002 int err = EMAIL_ERROR_NONE;
1004 if ( ((err = emcore_get_mail_data(input_mail_id, output_mail_data)) != EMAIL_ERROR_NONE) || !output_mail_data)
1005 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
1007 EM_DEBUG_FUNC_END("err [%d]", err);
1012 /* -----------------------------------------------------------
1014 -----------------------------------------------------------*/
1016 EXPORT_API int email_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver)
1018 EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d],seen_flag[%d], on_server [ %d]", mail_ids, num, seen_flag, onserver);
1019 EM_DEBUG_FUNC_END("EMAIL_ERROR_NOT_IMPLEMENTED");
1020 return EMAIL_ERROR_NOT_IMPLEMENTED;
1023 EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, email_flags_field_type field_type, int value, int onserver)
1025 EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_ids[%p], num[%d], field_type [%d], seen_flag[%d], on_server [ %d]", account_id, mail_ids, num, field_type, value, onserver);
1027 int err = EMAIL_ERROR_NONE;
1030 EM_IF_NULL_RETURN_VALUE(mail_ids, EMAIL_ERROR_INVALID_PARAM);
1031 if (account_id == 0 || num <= 0 || (onserver != 0 && onserver != 1)) {
1032 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1033 return EMAIL_ERROR_INVALID_PARAM;
1036 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_FLAGS_FIELD);
1039 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1040 err = EMAIL_ERROR_NULL_VALUE;
1045 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
1046 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1047 err = EMAIL_ERROR_OUT_OF_MEMORY;
1051 /* Number of mail_ids */
1052 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
1053 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1054 err = EMAIL_ERROR_OUT_OF_MEMORY;
1058 /* set of mail_ids */
1059 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
1060 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1061 err = EMAIL_ERROR_OUT_OF_MEMORY;
1066 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&field_type, sizeof(int))) {
1067 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1068 err = EMAIL_ERROR_OUT_OF_MEMORY;
1073 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&value, sizeof(int))) {
1074 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1075 err = EMAIL_ERROR_OUT_OF_MEMORY;
1080 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
1081 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1082 err = EMAIL_ERROR_OUT_OF_MEMORY;
1087 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1088 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1089 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1093 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1097 emipc_destroy_email_api(hAPI);
1099 EM_DEBUG_FUNC_END("err [%d]", err);
1104 /* -----------------------------------------------------------
1106 -----------------------------------------------------------*/
1107 EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, int input_target_mailbox_id)
1109 EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num [%d], input_target_mailbox_id[%d]", mail_ids, num, input_target_mailbox_id);
1111 int err = EMAIL_ERROR_NONE;
1112 HIPC_API hAPI = NULL;
1114 if(input_target_mailbox_id <= 0) {
1115 EM_DEBUG_EXCEPTION("input_target_mailbox_id is invalid parameter");
1116 err = EMAIL_ERROR_INVALID_PARAM;
1119 EM_IF_NULL_RETURN_VALUE(mail_ids, EMAIL_ERROR_INVALID_PARAM);
1122 EM_DEBUG_LOG("num = %d", num);
1123 err = EMAIL_ERROR_INVALID_PARAM;
1127 hAPI = emipc_create_email_api(_EMAIL_API_MOVE_MAIL);
1130 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1131 err = EMAIL_ERROR_NULL_VALUE;
1135 /* Number of mail_ids */
1136 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
1137 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1138 err = EMAIL_ERROR_OUT_OF_MEMORY;
1142 /* set of mail_ids */
1143 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
1144 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1145 err = EMAIL_ERROR_OUT_OF_MEMORY;
1149 /* input_target_mailbox_id */
1150 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_target_mailbox_id, sizeof(int))) {
1151 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1152 err = EMAIL_ERROR_OUT_OF_MEMORY;
1157 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1158 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1159 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1163 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1167 emipc_destroy_email_api(hAPI);
1169 EM_DEBUG_FUNC_END("err [%d]", err);
1174 EXPORT_API int email_move_all_mails_to_mailbox(int input_source_mailbox_id, int input_target_mailbox_id)
1176 EM_DEBUG_FUNC_BEGIN("input_source_mailbox_id[%d] , input_target_mailbox_id[%d]", input_source_mailbox_id, input_target_mailbox_id);
1178 int err = EMAIL_ERROR_NONE;
1179 HIPC_API hAPI = NULL;
1181 if(input_source_mailbox_id <= 0 || input_target_mailbox_id <= 0) {
1182 EM_DEBUG_EXCEPTION("mailbox_id is invalid parameter");
1183 err = EMAIL_ERROR_INVALID_PARAM;
1187 hAPI = emipc_create_email_api(_EMAIL_API_MOVE_ALL_MAIL);
1190 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1191 err = EMAIL_ERROR_NULL_VALUE;
1195 /* input_source_mailbox_id */
1196 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_source_mailbox_id, sizeof(int))) {
1197 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1198 err = EMAIL_ERROR_OUT_OF_MEMORY;
1202 /* input_target_mailbox_id */
1203 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_target_mailbox_id, sizeof(int))) {
1204 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1205 err = EMAIL_ERROR_OUT_OF_MEMORY;
1210 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1211 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1212 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1216 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1220 emipc_destroy_email_api(hAPI);
1222 EM_DEBUG_FUNC_END("err [%d]", err);
1227 EXPORT_API int email_free_mail_data(email_mail_data_t** mail_list, int count)
1229 EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d]", mail_list, count);
1230 int err = EMAIL_ERROR_NONE;
1231 emcore_free_mail_data_list(mail_list, count);
1232 EM_DEBUG_FUNC_END("err [%d]", err);
1236 /* Convert Modified UTF-7 mailbox name to UTF-8 */
1237 /* returns modified UTF-8 Name if success else NULL */
1239 EXPORT_API int email_cancel_sending_mail( int mail_id)
1241 EM_DEBUG_FUNC_BEGIN("Mail ID [ %d]", mail_id);
1242 EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
1244 int err = EMAIL_ERROR_NONE;
1246 email_mail_data_t* mail_data = NULL;
1248 HIPC_API hAPI = NULL;
1251 if ((err = emcore_get_mail_data(mail_id, &mail_data)) != EMAIL_ERROR_NONE) {
1252 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
1257 EM_DEBUG_EXCEPTION("mail_data is null");
1258 err = EMAIL_ERROR_NULL_VALUE;
1262 account_id = mail_data->account_id;
1264 hAPI = emipc_create_email_api(_EMAIL_API_SEND_MAIL_CANCEL_JOB);
1267 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1268 err = EMAIL_ERROR_NULL_VALUE;
1273 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
1274 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1275 err = EMAIL_ERROR_OUT_OF_MEMORY;
1280 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1281 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1282 err = EMAIL_ERROR_OUT_OF_MEMORY;
1287 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1288 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1289 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1293 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1297 emipc_destroy_email_api(hAPI);
1299 emcore_free_mail_data_list(&mail_data, 1);
1301 EM_DEBUG_FUNC_END("err [%d]", err);
1306 EXPORT_API int email_retry_sending_mail( int mail_id, int timeout_in_sec)
1308 EM_DEBUG_FUNC_BEGIN();
1310 int err = EMAIL_ERROR_NONE;
1313 EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
1314 if( timeout_in_sec < 0 ) {
1315 EM_DEBUG_EXCEPTION("Invalid timeout_in_sec");
1316 err = EMAIL_ERROR_INVALID_PARAM;
1320 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_RETRY);
1323 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1324 err = EMAIL_ERROR_NULL_VALUE;
1329 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1330 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1331 err = EMAIL_ERROR_OUT_OF_MEMORY;
1336 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(timeout_in_sec), sizeof(int))) {
1337 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1338 err = EMAIL_ERROR_OUT_OF_MEMORY;
1343 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1344 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1345 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1349 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1353 emipc_destroy_email_api(hAPI);
1355 EM_DEBUG_FUNC_END("err [%d]", err);
1360 EXPORT_API int email_get_max_mail_count(int *Count)
1362 EM_DEBUG_FUNC_BEGIN();
1363 int err = EMAIL_ERROR_NONE;
1364 EM_IF_NULL_RETURN_VALUE(Count, EMAIL_ERROR_INVALID_PARAM);
1365 *Count = emstorage_get_max_mail_count();
1366 EM_DEBUG_FUNC_END("err [%d]", err);
1372 /* for setting application,disk usage of email in KB */
1373 EXPORT_API int email_get_disk_space_usage(unsigned long *total_size)
1375 EM_DEBUG_FUNC_BEGIN("total_size[%p]", total_size);
1376 int err = EMAIL_ERROR_NONE;
1378 EM_IF_NULL_RETURN_VALUE(total_size, EMAIL_ERROR_INVALID_PARAM);
1380 if (!emstorage_mail_get_total_diskspace_usage(total_size,true,&err)) {
1381 EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage failed [%d]", err);
1386 EM_DEBUG_FUNC_END("err [%d]", err);
1390 EXPORT_API int email_get_address_info_list(int mail_id, email_address_info_list_t** address_info_list)
1392 EM_DEBUG_FUNC_BEGIN("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
1394 int err = EMAIL_ERROR_NONE;
1396 email_address_info_list_t *temp_address_info_list = NULL;
1398 EM_IF_NULL_RETURN_VALUE(address_info_list, EMAIL_ERROR_INVALID_PARAM);
1400 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
1401 err = EMAIL_ERROR_INVALID_PARAM ;
1405 if ( !emcore_get_mail_address_info_list(mail_id, &temp_address_info_list, &err) ) {
1406 EM_DEBUG_EXCEPTION("emcore_get_mail_address_info_list failed [%d]", err);
1411 if ( address_info_list ) {
1412 *address_info_list = temp_address_info_list;
1413 temp_address_info_list = NULL;
1417 if ( temp_address_info_list )
1418 emstorage_free_address_info_list(&temp_address_info_list);
1419 EM_DEBUG_FUNC_END("err [%d]", err);
1423 EXPORT_API int email_free_address_info_list(email_address_info_list_t **address_info_list)
1425 EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
1427 int err = EMAIL_ERROR_NONE;
1429 if ( (err = emstorage_free_address_info_list(address_info_list)) != EMAIL_ERROR_NONE ) {
1430 EM_DEBUG_EXCEPTION("address_info_list[%p] free failed.", address_info_list);
1432 EM_DEBUG_FUNC_END("err [%d]", err);
1436 EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, email_convert_struct_type_e type)
1438 EM_DEBUG_FUNC_BEGIN("encoded_string[%s], struct_var[%p], type[%d]", encoded_string, struct_var, type);
1440 int err = EMAIL_ERROR_NONE;
1441 void * temp_struct = NULL;
1443 EM_IF_NULL_RETURN_VALUE(encoded_string, EMAIL_ERROR_INVALID_PARAM);
1444 EM_IF_NULL_RETURN_VALUE(struct_var, EMAIL_ERROR_INVALID_PARAM);
1446 if ( (err = emcore_convert_string_to_structure((char*)encoded_string, &temp_struct, type)) != EMAIL_ERROR_NONE ) {
1447 EM_DEBUG_EXCEPTION("emcore_convert_string_to_structure failed[%d]", err);
1452 *struct_var = temp_struct;
1455 EM_DEBUG_FUNC_END("err [%d]", err);
1459 EXPORT_API int email_get_meeting_request(int mail_id, email_meeting_request_t **meeting_req)
1461 EM_DEBUG_FUNC_BEGIN("mail_id[%d],meeting_req[%p]", mail_id, meeting_req);
1463 int err = EMAIL_ERROR_NONE;
1465 email_meeting_request_t *temp_meeting_req = NULL;
1467 EM_IF_NULL_RETURN_VALUE(meeting_req, EMAIL_ERROR_INVALID_PARAM);
1468 if( mail_id <= 0 ) {
1469 EM_DEBUG_EXCEPTION(" Invalid Mail Id Param ");
1470 err = EMAIL_ERROR_INVALID_PARAM ;
1474 if ( !emstorage_get_meeting_request(mail_id, &temp_meeting_req, 1, &err) ) {
1475 EM_DEBUG_EXCEPTION("emstorage_get_meeting_request -- Failed [%d]", err);
1481 *meeting_req = temp_meeting_req;
1484 EM_DEBUG_FUNC_END("err [%d]", err);
1488 EXPORT_API int email_free_meeting_request(email_meeting_request_t** meeting_req, int count)
1490 EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d]", meeting_req, count);
1491 if( !meeting_req | !*meeting_req ) {
1492 EM_DEBUG_EXCEPTION("NULL PARAM");
1493 return EMAIL_ERROR_INVALID_PARAM;
1497 email_meeting_request_t *cur = *meeting_req;
1498 for ( ; i < count ; i++ )
1499 emstorage_free_meeting_request(cur + i);
1501 EM_SAFE_FREE(*meeting_req);
1503 EM_DEBUG_FUNC_END();
1504 return EMAIL_ERROR_NONE;
1507 EXPORT_API int email_move_thread_to_mailbox(int thread_id, int target_mailbox_id, int move_always_flag)
1509 EM_DEBUG_FUNC_BEGIN("thread_id[%d], target_mailbox_id[%d], move_always_flag[%d]", thread_id, target_mailbox_id, move_always_flag);
1510 int err = EMAIL_ERROR_NONE;
1513 EM_IF_NULL_RETURN_VALUE(target_mailbox_id, EMAIL_ERROR_INVALID_PARAM);
1515 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MOVE_THREAD_TO_MAILBOX);
1518 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1519 err = EMAIL_ERROR_NULL_VALUE;
1524 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
1525 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1526 err = EMAIL_ERROR_OUT_OF_MEMORY;
1530 /* target mailbox information */
1531 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&target_mailbox_id, sizeof(int))){
1532 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1533 err = EMAIL_ERROR_OUT_OF_MEMORY;
1537 /* move_always_flag */
1538 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&move_always_flag, sizeof(int))){
1539 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1540 err = EMAIL_ERROR_OUT_OF_MEMORY;
1545 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1546 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1547 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1551 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1555 emipc_destroy_email_api(hAPI);
1557 EM_DEBUG_FUNC_END("err [%d]", err);
1561 EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag)
1563 EM_DEBUG_FUNC_BEGIN("thread_id[%d], delete_always_flag[%d]", thread_id, delete_always_flag);
1564 int err = EMAIL_ERROR_NONE;
1566 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_THREAD);
1569 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1570 err = EMAIL_ERROR_NULL_VALUE;
1575 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
1576 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1577 err = EMAIL_ERROR_OUT_OF_MEMORY;
1581 /* delete_always_flag */
1582 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&delete_always_flag, sizeof(int))){
1583 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1584 err = EMAIL_ERROR_OUT_OF_MEMORY;
1589 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1590 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1591 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1595 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1599 emipc_destroy_email_api(hAPI);
1601 EM_DEBUG_FUNC_END("err [%d]", err);
1605 EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server)
1607 EM_DEBUG_FUNC_BEGIN("thread_id[%d], seen_flag[%d], on_server[%d]", thread_id, seen_flag, on_server);
1608 int err = EMAIL_ERROR_NONE;
1609 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD);
1612 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1613 err = EMAIL_ERROR_NULL_VALUE;
1618 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))) {
1619 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1620 err = EMAIL_ERROR_OUT_OF_MEMORY;
1625 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&seen_flag, sizeof(int))) {
1626 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1627 err = EMAIL_ERROR_OUT_OF_MEMORY;
1632 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&on_server, sizeof(int))) {
1633 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1634 err = EMAIL_ERROR_OUT_OF_MEMORY;
1639 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1640 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1641 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1645 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1649 emipc_destroy_email_api(hAPI);
1650 EM_DEBUG_FUNC_END("err [%d]", err);
1654 EXPORT_API int email_expunge_mails_deleted_flagged(int input_mailbox_id, int input_on_server, unsigned *output_handle)
1656 EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], input_on_server[%d], output_handle[%p]", input_mailbox_id, input_on_server, output_handle);
1657 int err = EMAIL_ERROR_NONE;
1658 int return_value = 0;
1659 HIPC_API hAPI = NULL;
1660 emstorage_mailbox_tbl_t *mailbox_tbl_data = NULL;
1662 if( (err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl_data)) != EMAIL_ERROR_NONE) {
1663 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed[%d]", err);
1667 email_account_server_t account_server_type = EMAIL_SERVER_TYPE_NONE;
1668 ASNotiData as_noti_data;
1670 memset(&as_noti_data, 0, sizeof(ASNotiData)); /* initialization of union members */
1672 if ( em_get_account_server_type_by_account_id(mailbox_tbl_data->account_id, &account_server_type, true, &err) == false ) {
1673 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
1677 if ( account_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC && input_on_server == true) {
1680 if ( em_get_handle_for_activesync(&as_handle, &err) == false ) {
1681 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync failed[%d].", err);
1685 /* noti to active sync */
1686 as_noti_data.expunge_mails_deleted_flagged.handle = as_handle;
1687 as_noti_data.expunge_mails_deleted_flagged.mailbox_id = input_mailbox_id;
1688 as_noti_data.expunge_mails_deleted_flagged.on_server = input_on_server;
1690 return_value = em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_EXPUNGE_MAILS_DELETED_FLAGGED, &as_noti_data);
1692 if ( return_value == false ) {
1693 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed.");
1694 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
1699 *output_handle = as_handle;
1703 hAPI = emipc_create_email_api(_EMAIL_API_EXPUNGE_MAILS_DELETED_FLAGGED);
1706 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1707 err = EMAIL_ERROR_NULL_VALUE;
1711 /* input_mailbox_id */
1712 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_mailbox_id, sizeof(int))) {
1713 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1714 err = EMAIL_ERROR_OUT_OF_MEMORY;
1718 /* input_on_server */
1719 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_on_server, sizeof(int))) {
1720 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1721 err = EMAIL_ERROR_OUT_OF_MEMORY;
1726 if(emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
1727 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1728 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
1732 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1733 if (err == EMAIL_ERROR_NONE) {
1735 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_handle);
1741 emipc_destroy_email_api(hAPI);
1743 if(mailbox_tbl_data) {
1744 emstorage_free_mailbox(&mailbox_tbl_data, 1, NULL);
1747 EM_DEBUG_FUNC_END("err [%d]", err);