upload tizen1.0 source
[framework/messaging/email-service.git] / email-api / email-api-mail.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21
22
23
24 /**
25  *
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 
30  *                      email-service . 
31  */
32
33 #include <stdlib.h>
34 #include <time.h>
35 #include <string.h>
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"
44 #include "db-util.h"
45
46 #define  DIR_SEPERATOR_CH '/'
47
48 #define _DIRECT_TO_DB
49
50 EXPORT_API int email_add_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_from_eas)
51 {
52         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);
53
54         EM_IF_NULL_RETURN_VALUE(input_mail_data,               EMF_ERROR_INVALID_PARAM);
55         EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id,   EMF_ERROR_INVALID_PARAM);
56         EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_name, EMF_ERROR_INVALID_PARAM);
57
58         if(input_attachment_count > 0 && !input_attachment_data_list) {
59                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
60                 return EMF_ERROR_INVALID_PARAM;
61         }
62
63         int       err = EMF_ERROR_NONE;
64         int       size = 0;
65         char     *mail_data_stream = NULL;
66         char     *attachment_data_list_stream  = NULL;
67         char     *meeting_request_stream = NULL;
68         HIPC_API  hAPI = NULL;
69         
70         if(input_from_eas == 0) {
71                 hAPI = emipc_create_email_api(_EMAIL_API_ADD_MAIL);
72
73                 if(!hAPI) {
74                         EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
75                         err = EMF_ERROR_NULL_VALUE;             
76                         goto FINISH_OFF;
77                 }
78
79                 /* emf_mail_data_t */
80                 mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
81
82                 if(!mail_data_stream) {
83                         EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
84                         err = EMF_ERROR_NULL_VALUE;
85                         goto FINISH_OFF;
86                 }
87
88                 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
89                         EM_DEBUG_EXCEPTION("emipc_add_parameter for head failed");
90                         err = EMF_ERROR_OUT_OF_MEMORY;
91                         goto FINISH_OFF;
92                 }
93                 
94                 /* emf_attachment_data_t */
95                 attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
96
97                 if(!attachment_data_list_stream) {
98                         EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
99                         err = EMF_ERROR_NULL_VALUE;
100                         goto FINISH_OFF;
101                 }
102
103                 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
104                         EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
105                         err = EMF_ERROR_OUT_OF_MEMORY;
106                         goto FINISH_OFF;
107                 }
108
109                 /*  emf_meeting_request_t */
110                 if ( input_mail_data->meeting_request_status != EMF_MAIL_TYPE_NORMAL ) {
111                         meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
112
113                         if(!meeting_request_stream) {
114                                 EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
115                                 err = EMF_ERROR_NULL_VALUE;
116                                 goto FINISH_OFF;
117                         }
118
119                         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
120                                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
121                                 err = EMF_ERROR_OUT_OF_MEMORY;
122                                 goto FINISH_OFF;
123                         }
124                 }
125
126                 /* input_from_eas */
127                 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int))) {
128                         EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
129                         err = EMF_ERROR_OUT_OF_MEMORY;
130                         goto FINISH_OFF;
131                 }
132
133                 /* Execute API */
134                 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
135                         EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
136                         err = EMF_ERROR_IPC_SOCKET_FAILURE;
137                         goto FINISH_OFF;
138                 }
139
140                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
141
142                 if(err == EMF_ERROR_NONE) {
143                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &input_mail_data->mail_id); /* result mail_id */
144                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), &input_mail_data->thread_id); /* result thread_id */
145                 }
146         } 
147         else {
148                 if((err = emcore_add_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMF_ERROR_NONE) {
149                         EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err);
150                         goto FINISH_OFF;
151                 }
152         }
153
154 FINISH_OFF:
155         if(hAPI) 
156                 emipc_destroy_email_api(hAPI);
157
158         EM_SAFE_FREE(mail_data_stream);
159         EM_SAFE_FREE(attachment_data_list_stream);
160
161         EM_DEBUG_FUNC_END("err [%d]", err);
162         return err;
163
164 }
165
166 EXPORT_API int email_add_read_receipt(int input_read_mail_id, int *output_receipt_mail_id)
167 {
168         EM_DEBUG_FUNC_BEGIN("input_read_mail_id [%d], output_receipt_mail_id [%p]", input_read_mail_id, output_receipt_mail_id);
169
170         EM_IF_NULL_RETURN_VALUE(output_receipt_mail_id, EMF_ERROR_INVALID_PARAM);
171
172         int      err = EMF_ERROR_NONE;
173         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_READ_RECEIPT);
174
175         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
176
177         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &input_read_mail_id, sizeof(int))) {
178                 EM_DEBUG_EXCEPTION("Add Param mail body Fail");
179                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_NULL_VALUE);
180         }
181
182         /* Execute API */
183         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
184                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
185                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
186         }
187
188         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
189
190         EM_DEBUG_LOG("err [%d]", err);
191
192         if(err == EMF_ERROR_NONE) {
193                 /* Get receipt mail id */
194                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), output_receipt_mail_id);
195                 EM_DEBUG_LOG("output_receipt_mail_id [%d]", *output_receipt_mail_id);
196         }
197
198         emipc_destroy_email_api(hAPI);
199
200         hAPI = NULL;
201
202         EM_DEBUG_FUNC_END("err [%d]", err);
203         return err;
204 }
205
206
207 int email_create_db_full()
208 {
209         int mailbox_index, mail_index, mailbox_count, mail_slot_size;
210         emstorage_mail_tbl_t mail_table_data = {0};
211         emf_mailbox_t *mailbox_list = NULL;
212         int err = EMF_ERROR_NONE;
213
214         if ( (err = email_open_db()) != EMF_ERROR_NONE) {
215                 EM_DEBUG_EXCEPTION("email_open_db failed [%d]", err);
216                 return err;
217         }
218
219         mail_table_data.subject = (char*) em_malloc(50); 
220         mail_table_data.full_address_from = strdup("<dummy_from@nowhere.com>");
221         mail_table_data.full_address_to = strdup("<dummy_to@nowhere.com>");
222         mail_table_data.account_id =1;
223         mail_table_data.mailbox_name = (char*) em_malloc(250);
224
225         if( (err = email_get_mailbox_list_ex(1, -1, 0, &mailbox_list, &mailbox_count)) < EMF_ERROR_NONE) {
226                 EM_DEBUG_EXCEPTION("email_get_mailbox_list_ex failed [%d]", err);
227                 goto FINISH_OFF;
228         }
229
230         for(mailbox_index = 0; mailbox_index < mailbox_count; mailbox_index++) {
231                 mail_slot_size= mailbox_list[mailbox_index].mail_slot_size;
232                 for(mail_index = 0; mail_index < mail_slot_size; mail_index++) {
233                         sprintf(mail_table_data.subject, "Subject #%d",mail_index);
234                         strncpy(mail_table_data.mailbox_name, mailbox_list[mailbox_index].name, 250 - 1);
235                         mail_table_data.mailbox_type = mailbox_list[mailbox_index].mailbox_type;
236                         if( !emstorage_add_mail(&mail_table_data, 1, true, &err))  {
237                                 EM_DEBUG_EXCEPTION("emstorage_add_mail failed [%d]",err);
238                 
239                                 goto FINISH_OFF;
240                         }
241                 }
242         }
243
244 FINISH_OFF:
245         if ( (err = email_close_db()) != EMF_ERROR_NONE) {
246                 EM_DEBUG_EXCEPTION("email_close_db failed [%d]", err);
247         }       
248         
249         if(mailbox_list)
250                 email_free_mailbox(&mailbox_list, mailbox_count);
251
252         EM_SAFE_FREE(mail_table_data.subject);
253         EM_SAFE_FREE(mail_table_data.mailbox_name);
254         EM_SAFE_FREE(mail_table_data.full_address_from);
255         EM_SAFE_FREE(mail_table_data.full_address_to);
256
257         return err;
258 }
259
260 EXPORT_API int email_update_mail(emf_mail_data_t *input_mail_data, emf_attachment_data_t *input_attachment_data_list, int input_attachment_count, emf_meeting_request_t* input_meeting_request, int input_from_eas)
261 {
262         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);
263
264         EM_IF_NULL_RETURN_VALUE(input_mail_data,               EMF_ERROR_INVALID_PARAM);
265         EM_IF_NULL_RETURN_VALUE(input_mail_data->account_id,   EMF_ERROR_INVALID_PARAM);
266         EM_IF_NULL_RETURN_VALUE(input_mail_data->mailbox_name, EMF_ERROR_INVALID_PARAM);
267
268         if(input_attachment_count > 0 && !input_attachment_data_list) {
269                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
270                 return EMF_ERROR_INVALID_PARAM;
271         }
272
273         int       err = EMF_ERROR_NONE;
274         int       size = 0;
275         char     *mail_data_stream = NULL;
276         char     *attachment_data_list_stream  = NULL;
277         char     *meeting_request_stream = NULL;
278
279         HIPC_API  hAPI = NULL;
280         
281         if(input_from_eas == 0) {
282                 hAPI = emipc_create_email_api(_EMAIL_API_UPDATE_MAIL);  
283
284                 if(!hAPI) {
285                         EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
286                         err = EMF_ERROR_NULL_VALUE;             
287                         goto FINISH_OFF;
288                 }
289
290                 /* emf_mail_data_t */
291                 mail_data_stream = em_convert_mail_data_to_byte_stream(input_mail_data, 1, &size);
292
293                 if(!mail_data_stream) {
294                         EM_DEBUG_EXCEPTION("em_convert_mail_data_to_byte_stream failed");
295                         err = EMF_ERROR_NULL_VALUE;
296                         goto FINISH_OFF;
297                 }
298                 
299                 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mail_data_stream, size)) {
300                         EM_DEBUG_EXCEPTION("emipc_add_parameter for head failed");
301                         err = EMF_ERROR_OUT_OF_MEMORY;
302                         goto FINISH_OFF;
303                 }
304                 
305                 /* emf_attachment_data_t */
306                 attachment_data_list_stream = em_convert_attachment_data_to_byte_stream(input_attachment_data_list, input_attachment_count, &size);
307
308                 if(!attachment_data_list_stream) {
309                         EM_DEBUG_EXCEPTION("em_convert_attachment_data_to_byte_stream failed");
310                         err = EMF_ERROR_NULL_VALUE;
311                         goto FINISH_OFF;
312                 }
313
314                 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, attachment_data_list_stream, size)) {
315                         EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
316                         err = EMF_ERROR_OUT_OF_MEMORY;
317                         goto FINISH_OFF;
318                 }
319
320                 /*  emf_meeting_request_t */
321                 if ( input_mail_data->meeting_request_status != EMF_MAIL_TYPE_NORMAL ) {
322                         meeting_request_stream = em_convert_meeting_req_to_byte_stream(input_meeting_request, &size);
323
324                         if(!meeting_request_stream) {
325                                 EM_DEBUG_EXCEPTION("em_convert_meeting_req_to_byte_stream failed");
326                                 err = EMF_ERROR_NULL_VALUE;
327                                 goto FINISH_OFF;
328                         }
329
330                         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, meeting_request_stream, size)) {
331                                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
332                                 err = EMF_ERROR_OUT_OF_MEMORY;
333                                 goto FINISH_OFF;
334                         }
335                 }
336
337                 /* input_from_eas */
338                 if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&input_from_eas, sizeof(int))) {
339                         EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
340                         err = EMF_ERROR_OUT_OF_MEMORY;
341                         goto FINISH_OFF;
342                 }
343
344                 /* Execute API */
345                 if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
346                         EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
347                         err = EMF_ERROR_IPC_SOCKET_FAILURE;
348                         goto FINISH_OFF;
349                 }
350
351                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
352                 
353                 if(err == EMF_ERROR_NONE) {
354                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &input_mail_data->mail_id);
355                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 2, sizeof(int), &input_mail_data->thread_id);
356                 }
357         } 
358         else {
359                 if( (err = emcore_update_mail(input_mail_data, input_attachment_data_list, input_attachment_count, input_meeting_request, input_from_eas)) != EMF_ERROR_NONE) {
360                         EM_DEBUG_EXCEPTION("emcore_update_mail failed [%d]", err);
361                         goto FINISH_OFF;
362                 }
363         }
364
365 FINISH_OFF:
366         if(hAPI) 
367                 emipc_destroy_email_api(hAPI);
368
369         EM_SAFE_FREE(mail_data_stream);
370         EM_SAFE_FREE(attachment_data_list_stream);
371
372         EM_DEBUG_FUNC_END("err [%d]", err);
373         return err;
374
375 }
376
377 EXPORT_API int email_clear_mail_data()
378 {
379         EM_DEBUG_FUNC_BEGIN();
380         int err = EMF_ERROR_NONE;
381         
382         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_CLEAR_DATA);  
383
384         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
385         
386         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
387                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api Fail");
388                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
389         }
390         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
391         
392         if(hAPI)
393                 emipc_destroy_email_api(hAPI);
394
395         EM_DEBUG_FUNC_END("err [%d]", err);
396         return err;
397 }
398
399
400 EXPORT_API int email_count_message(emf_mailbox_t* mailbox, int* total, int* unseen)
401 {
402         EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
403         
404         int total_count = 0;
405         int unread = 0;
406         int err = EMF_ERROR_NONE;
407
408         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
409         EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
410         EM_IF_NULL_RETURN_VALUE(unseen, EMF_ERROR_INVALID_PARAM);
411
412         if (!emstorage_get_mail_count(mailbox->account_id,  mailbox->name, &total_count, &unread, true, &err)) {
413                 EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
414
415         } else {
416                 *total = total_count;
417                 *unseen = unread;
418         }
419         EM_DEBUG_FUNC_END("err [%d]", err);
420         return err;
421 }
422
423
424
425
426 EXPORT_API int  email_count_message_all_mailboxes(emf_mailbox_t* mailbox, int* total, int* unseen)
427 {
428         EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p], unseen[%p]", mailbox, total, unseen);
429         
430         int total_count = 0;
431         int unread = 0;
432         int err = EMF_ERROR_NONE;
433                 
434         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
435         EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
436         EM_IF_NULL_RETURN_VALUE(unseen, EMF_ERROR_INVALID_PARAM);
437         EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
438
439     if (!emstorage_get_mail_count(mailbox->account_id,  NULL, &total_count, &unread, true, &err)) {
440                 EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
441
442         } else {
443                 *total = total_count;
444                 *unseen = unread;
445         }
446         EM_DEBUG_FUNC_END("err [%d]", err);
447         return err;
448 }
449
450
451
452 EXPORT_API int email_delete_message(emf_mailbox_t* mailbox, int *mail_ids, int num, int from_server)
453 {
454         EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%p], num[%d], from_server[%d]", mailbox, mail_ids, num, from_server);
455
456         char* mailbox_stream = NULL;
457         int size = 0;
458         int err = EMF_ERROR_NONE;
459         HIPC_API hAPI = NULL;
460
461         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
462         EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
463         EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
464         
465         if (num <= 0) {
466                 EM_DEBUG_EXCEPTION("num = %d", num);
467                 err = EMF_ERROR_INVALID_PARAM;          
468                 return err;
469         }
470
471         hAPI = emipc_create_email_api(_EMAIL_API_DELETE_MAIL);
472         
473         if(!hAPI) {
474                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
475                 err = EMF_ERROR_NULL_VALUE;             
476                 goto FINISH_OFF;
477         }
478
479         /* mailbox */
480         mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
481
482         if(!mailbox_stream) {
483                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
484                 err = EMF_ERROR_NULL_VALUE;             
485                 goto FINISH_OFF;
486         }
487         
488         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
489                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
490                 err = EMF_ERROR_OUT_OF_MEMORY;          
491                 goto FINISH_OFF;
492         }
493
494         /* Number of mail_ids */
495         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
496                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
497                 err = EMF_ERROR_OUT_OF_MEMORY;          
498                 goto FINISH_OFF;
499         }
500         
501         /* set of mail_ids */
502         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
503                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
504                 err = EMF_ERROR_OUT_OF_MEMORY;          
505                 goto FINISH_OFF;
506         }
507         
508         /* from-server */
509         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&from_server, sizeof(int))) {
510                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
511                 err = EMF_ERROR_OUT_OF_MEMORY;          
512                 goto FINISH_OFF;
513         }
514         
515         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
516                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
517                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
518                 goto FINISH_OFF;
519         }
520
521         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
522
523 FINISH_OFF:
524         if(hAPI)
525                 emipc_destroy_email_api(hAPI);
526
527         EM_SAFE_FREE(mailbox_stream); 
528
529         EM_DEBUG_FUNC_END("err [%d]", err);
530         return err;
531 }
532
533
534 EXPORT_API int email_delete_all_message_in_mailbox(emf_mailbox_t* mailbox, int from_server)
535 {
536         EM_DEBUG_FUNC_BEGIN("mailbox[%p], from_server[%d]", mailbox, from_server);
537
538         char* mailbox_stream = NULL;
539         int size = 0;
540         int err = EMF_ERROR_NONE;
541         HIPC_API hAPI = NULL;
542         
543         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
544         EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
545         
546         hAPI =emipc_create_email_api(_EMAIL_API_DELETE_ALL_MAIL);       
547
548         if(!hAPI) {
549                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
550                 err = EMF_ERROR_NULL_VALUE;             
551                 goto FINISH_OFF;
552         }
553
554         mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
555
556         if(!mailbox_stream) {
557                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
558                 err = EMF_ERROR_NULL_VALUE;             
559                 goto FINISH_OFF;
560         }
561         
562         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
563                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
564                 err = EMF_ERROR_OUT_OF_MEMORY;          
565                 goto FINISH_OFF;
566         }
567
568         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&from_server, sizeof(int))){
569                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
570                 err = EMF_ERROR_OUT_OF_MEMORY;          
571                 goto FINISH_OFF;
572         }
573         
574         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
575                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
576                 err = EMF_ERROR_IPC_SOCKET_FAILURE;             
577                 goto FINISH_OFF;
578         }
579         
580         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int),&err );
581
582 FINISH_OFF:
583
584         if(hAPI)        
585                 emipc_destroy_email_api(hAPI);
586
587         EM_SAFE_FREE(mailbox_stream);
588         
589         EM_DEBUG_FUNC_END("err [%d]", err);
590         return err;
591 }
592
593
594
595 EXPORT_API int email_add_attachment( emf_mailbox_t* mailbox, int mail_id, emf_attachment_info_t* attachment)
596 {
597         EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment[%p]", mailbox, mail_id, attachment);
598         int err = EMF_ERROR_NONE;
599         char* mailbox_stream = NULL;
600         char* pAttchStream = NULL;
601         int size = 0;
602         HIPC_API hAPI = NULL;
603         
604         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
605         EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
606         EM_IF_NULL_RETURN_VALUE(attachment, EMF_ERROR_INVALID_PARAM);
607         EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM);
608         
609         hAPI = emipc_create_email_api(_EMAIL_API_ADD_ATTACHMENT);
610
611         if(!hAPI) {
612                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
613                 err = EMF_ERROR_NULL_VALUE;             
614                 goto FINISH_OFF;
615         }
616
617         /* Mailbox */
618         mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
619
620         if(!mailbox_stream) {
621                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
622                 err = EMF_ERROR_NULL_VALUE;             
623                 goto FINISH_OFF;
624         }
625
626         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
627                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
628                 err = EMF_ERROR_OUT_OF_MEMORY;          
629                 goto FINISH_OFF;
630         }
631
632         /* mail_id */
633         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
634                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
635                 err = EMF_ERROR_OUT_OF_MEMORY;          
636                 goto FINISH_OFF;
637         }
638
639         /* Attachment */
640         pAttchStream = em_convert_attachment_info_to_byte_stream(attachment, &size);
641
642         if(!pAttchStream) {
643                 EM_DEBUG_EXCEPTION("em_convert_attachment_info_to_byte_stream failed");
644                 err = EMF_ERROR_NULL_VALUE;             
645                 goto FINISH_OFF;
646         }
647
648         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pAttchStream, size)){
649                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
650                 err = EMF_ERROR_OUT_OF_MEMORY;          
651                 goto FINISH_OFF;
652         }
653
654         /* Execute API */
655         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
656                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
657                 err = EMF_ERROR_IPC_SOCKET_FAILURE;             
658                 goto FINISH_OFF;
659         }
660
661         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
662         
663         if(EMF_ERROR_NONE == err) {
664                 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), &attachment->attachment_id);
665         }
666
667 FINISH_OFF:
668         EM_SAFE_FREE(mailbox_stream);
669         EM_SAFE_FREE(pAttchStream);
670         
671         if(hAPI)
672                 emipc_destroy_email_api(hAPI);
673         
674         EM_DEBUG_FUNC_END("err [%d]", err);
675         return err;
676  }
677
678
679 EXPORT_API int email_delete_attachment(emf_mailbox_t * mailbox, int mail_id, const char *attachment_id)
680 {
681         EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s]", mailbox, mail_id, attachment_id);
682         int err = EMF_ERROR_NONE;
683         char* mailbox_stream = NULL;
684         int size = 0;
685
686         HIPC_API hAPI = NULL;
687         
688         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
689         EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
690         EM_IF_NULL_RETURN_VALUE(attachment_id, EMF_ERROR_INVALID_PARAM);
691         
692         hAPI = emipc_create_email_api(_EMAIL_API_DELETE_ATTACHMENT);
693         
694         if(!hAPI) {
695                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
696                 err = EMF_ERROR_NULL_VALUE;             
697                 goto FINISH_OFF;
698         }
699
700         /* Mailbox */
701         mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
702
703         if(!mailbox_stream) {
704                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
705                 err = EMF_ERROR_NULL_VALUE;             
706                 goto FINISH_OFF;
707         }
708
709         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
710                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
711                 err = EMF_ERROR_OUT_OF_MEMORY;          
712                 goto FINISH_OFF;
713         }
714
715         /* mail_id */
716         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
717                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
718                 err = EMF_ERROR_OUT_OF_MEMORY;          
719                 goto FINISH_OFF;
720         }
721
722         /* attachment_id */
723         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)attachment_id, strlen(attachment_id))) {
724                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
725                 err = EMF_ERROR_OUT_OF_MEMORY;          
726                 goto FINISH_OFF;
727         }
728
729         /* Execute API */
730         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
731                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
732                 err = EMF_ERROR_IPC_SOCKET_FAILURE;             
733                 goto FINISH_OFF;
734         }
735
736         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
737
738 FINISH_OFF:
739         if(hAPI)
740                 emipc_destroy_email_api(hAPI);
741
742         EM_SAFE_FREE(mailbox_stream);
743
744         return err;
745 }
746
747 /* -----------------------------------------------------------
748                                               Mail Search API
749     -----------------------------------------------------------*/
750
751 EXPORT_API int email_query_mails(char *conditional_clause_string, emf_mail_data_t** mail_list,  int *result_count)
752 {
753         EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
754
755         int err = EMF_ERROR_NONE;
756         emstorage_mail_tbl_t *result_mail_tbl;
757         
758         EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
759         EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMF_ERROR_INVALID_PARAM);
760
761         if (!emstorage_query_mail_tbl(conditional_clause_string, true, &result_mail_tbl, result_count, &err)) {
762                 EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err);
763
764                 goto FINISH_OFF;
765         }
766
767         if(!em_convert_mail_tbl_to_mail_data(result_mail_tbl, *result_count, mail_list, &err)) {
768                 EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
769                 goto FINISH_OFF;
770         }
771
772 FINISH_OFF:     
773         if(result_mail_tbl && !emstorage_free_mail(&result_mail_tbl, *result_count, &err))
774                 EM_DEBUG_EXCEPTION("emstorage_free_mail failed [%d]", err);
775
776         EM_DEBUG_FUNC_END("err [%d]", err);
777         return err;
778 }
779
780 EXPORT_API int email_query_message_ex(char *conditional_clause_string, emf_mail_list_item_t** mail_list,  int *result_count)
781 {
782         EM_DEBUG_FUNC_BEGIN("conditional_clause_string [%s], mail_list [%p], result_count [%p]", conditional_clause_string, mail_list, result_count);
783
784         int err = EMF_ERROR_NONE;
785         
786         EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
787         EM_IF_NULL_RETURN_VALUE(conditional_clause_string, EMF_ERROR_INVALID_PARAM);
788
789         if (!emstorage_query_mail_list(conditional_clause_string, true, mail_list, result_count, &err)) {
790                 EM_DEBUG_EXCEPTION("emstorage_query_mail_list failed [%d]", err);
791
792                 goto FINISH_OFF;
793         }
794
795 FINISH_OFF:     
796         EM_DEBUG_FUNC_END("err [%d]", err);
797         return err;
798 }
799
800
801 /* -----------------------------------------------------------
802                                               Mail Get Info API
803     -----------------------------------------------------------*/
804 EXPORT_API int email_get_attachment_info(emf_mailbox_t* mailbox, int mail_id, const char* attachment_id, emf_attachment_info_t** attachment)
805 {
806         EM_DEBUG_FUNC_BEGIN("mailbox[%p], mail_id[%d], attachment_id[%s], attachment[%p]", mailbox, mail_id, attachment_id, attachment);
807         
808         int err = EMF_ERROR_NONE;
809         int size = 0;
810         int nSize = 0;
811         char* mailbox_stream = NULL;
812         char* pAttchStream = NULL;
813         emf_attachment_info_t* pAttch = NULL;
814         
815
816         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
817         EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
818         EM_IF_NULL_RETURN_VALUE(attachment_id, EMF_ERROR_INVALID_PARAM);
819         EM_IF_NULL_RETURN_VALUE(attachment, EMF_ERROR_INVALID_PARAM);
820         EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
821         
822         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_GET_ATTACHMENT);
823
824         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
825
826         /* Mailbox */
827         mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
828
829         if(!mailbox_stream) {
830                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
831                 err = EMF_ERROR_NULL_VALUE;             
832                 goto FINISH_OFF;
833         }
834
835         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
836                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
837                 err = EMF_ERROR_OUT_OF_MEMORY;          
838                 goto FINISH_OFF;
839         }
840
841         /* mail_id */
842         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&mail_id, sizeof(int))) {
843                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
844                 err = EMF_ERROR_OUT_OF_MEMORY;          
845                 goto FINISH_OFF;
846         }
847
848         
849         /* attachment_id */
850         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)attachment_id, strlen(attachment_id))) {
851                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
852                 err = EMF_ERROR_OUT_OF_MEMORY;          
853                 goto FINISH_OFF;
854         }
855
856         /* Execute API */
857         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
858                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
859                 err = EMF_ERROR_IPC_SOCKET_FAILURE;             
860                 goto FINISH_OFF;
861         }
862
863         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
864
865         if(EMF_ERROR_NONE == err) {
866                 nSize = emipc_get_parameter_length(hAPI, ePARAMETER_OUT, 1);
867                 if(nSize > 0) {
868                         pAttchStream = (char*)em_malloc(nSize+1);
869
870                         if(!pAttchStream) {
871                                 EM_DEBUG_EXCEPTION("em_malloc failed");
872                                 err = EMF_ERROR_OUT_OF_MEMORY;          
873                                 goto FINISH_OFF;
874                         }       
875                 
876                         emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, nSize, pAttchStream);
877                         em_convert_byte_stream_to_attachment_info(pAttchStream, 1, &pAttch);
878                 }
879                 
880                 if(!pAttch) {
881                         EM_DEBUG_EXCEPTION("EMF_ERROR_NULL_VALUE");
882                         err = EMF_ERROR_NULL_VALUE;             
883                         goto FINISH_OFF;
884                 }
885
886                 *attachment = pAttch;
887         }
888
889 FINISH_OFF:
890         EM_SAFE_FREE(pAttchStream);
891
892         if(hAPI)
893                 emipc_destroy_email_api(hAPI);
894
895         EM_DEBUG_FUNC_END("err [%d]", err);
896         return err;
897
898 }
899
900 EXPORT_API int email_get_attachment_data_list(int input_mail_id, emf_attachment_data_t **output_attachment_data, int *output_attachment_count)
901 {
902         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);
903         int err = EMF_ERROR_NONE;
904         
905         if((err = emcore_get_attachment_data_list(input_mail_id, output_attachment_data, output_attachment_count)) != EMF_ERROR_NONE) {
906                 EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed [%d]", err);
907         }
908
909         EM_DEBUG_FUNC_END("err [%d]", err);
910         return err;
911 }
912
913 EXPORT_API int email_free_attachment_info(emf_attachment_info_t** atch_info)
914 {
915         EM_DEBUG_FUNC_BEGIN("atch_info[%p]", atch_info);        
916         
917         int err = EMF_ERROR_NONE;
918
919         if (!atch_info || !*atch_info)
920                 return EMF_ERROR_INVALID_PARAM;
921         
922         emf_attachment_info_t* p = *atch_info;
923         emf_attachment_info_t* t;
924         
925         while (p)  {
926                 EM_SAFE_FREE(p->name);
927                 EM_SAFE_FREE(p->savename);
928                 t = p->next;
929                 EM_SAFE_FREE(p);
930                 p = t;
931         }
932         EM_DEBUG_FUNC_END("err [%d]", err);
933         return err;
934 }
935
936 EXPORT_API int email_free_attachment_data(emf_attachment_data_t **attachment_data_list, int attachment_data_count)
937 {
938         EM_DEBUG_FUNC_BEGIN("attachment_data_list[%p], attachment_data_count[%d]", attachment_data_list, attachment_data_count);        
939         
940         int err = EMF_ERROR_NONE;
941
942         emcore_free_attachment_data(attachment_data_list, attachment_data_count, &err);
943         
944         EM_DEBUG_FUNC_END("err [%d]", err);
945         return err;
946 }
947
948
949 EXPORT_API int email_get_mails(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_data_t** mail_list,  int* result_count)
950 {
951         EM_DEBUG_FUNC_BEGIN();
952
953         int err = EMF_ERROR_NONE;
954         emstorage_mail_tbl_t *mail_tbl_list = NULL;
955         EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
956
957         if( account_id < ALL_ACCOUNT) {
958                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
959                 err = EMF_ERROR_INVALID_PARAM ;
960                 goto FINISH_OFF;
961         }
962
963         if (!emstorage_get_mails(account_id, (char*)mailbox_name, NULL, thread_id, start_index, limit_count, sorting, true, &mail_tbl_list, result_count, &err))  {
964                 EM_DEBUG_EXCEPTION("emstorage_get_mails failed [%d]", err);
965
966                 goto FINISH_OFF;
967         }
968
969         if(!em_convert_mail_tbl_to_mail_data(mail_tbl_list, *result_count, mail_list, &err)) {
970                 EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
971                 goto FINISH_OFF;
972         }
973
974 FINISH_OFF:     
975         if(mail_tbl_list && !emstorage_free_mail(&mail_tbl_list, *result_count, &err))
976                 EM_DEBUG_EXCEPTION("emstorage_free_mail failed [%d]", err);
977
978         EM_DEBUG_FUNC_END("err [%d]", err);
979         return err;
980 }
981
982 EXPORT_API int email_get_mail_list_ex(int account_id , const char *mailbox_name, int thread_id, int start_index, int limit_count, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list,  int* result_count)
983 {
984         EM_DEBUG_FUNC_BEGIN();
985
986         int err = EMF_ERROR_NONE;
987         
988         EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
989
990         if( account_id < ALL_ACCOUNT) {
991                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
992                 return EMF_ERROR_INVALID_PARAM;
993         }
994
995         if (!emstorage_get_mail_list(account_id, (char*) mailbox_name, NULL, thread_id, start_index, limit_count, 0, NULL, sorting, true, mail_list, result_count, &err))  {
996                 EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err);
997
998                 goto FINISH_OFF;
999         }
1000
1001 FINISH_OFF:     
1002         EM_DEBUG_FUNC_END("err [%d]", err);
1003         return err;
1004 }
1005
1006 EXPORT_API int email_find_mail (int account_id , const char *mailbox_name, int thread_id, 
1007         int search_type, char *search_value, int start_index, int limit_count,
1008         emf_sort_type_t sorting, emf_mail_list_item_t** mail_list,  int* result_count)
1009 {
1010         EM_DEBUG_FUNC_BEGIN();
1011         
1012         int err = EMF_ERROR_NONE;
1013         int search_num = 0;
1014         emf_mail_list_item_t* mail_list_item = NULL;
1015
1016         EM_IF_NULL_RETURN_VALUE(mail_list, EMF_ERROR_INVALID_PARAM);
1017         EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
1018         EM_IF_NULL_RETURN_VALUE(search_value, EMF_ERROR_INVALID_PARAM);
1019
1020         switch ( search_type ) {
1021                 case EMF_SEARCH_FILTER_SUBJECT:
1022                 case EMF_SEARCH_FILTER_SENDER:
1023                 case EMF_SEARCH_FILTER_RECIPIENT:
1024                 case EMF_SEARCH_FILTER_ALL:
1025                         break;
1026                 default:
1027                         EM_DEBUG_EXCEPTION("Invalid search filter type[%d]", search_type);
1028                         err = EMF_ERROR_INVALID_PARAM;
1029                         return err;
1030         }
1031
1032         if (!emstorage_get_searched_mail_list(account_id, (char*)mailbox_name, thread_id, search_type, search_value,  start_index, limit_count, sorting, true, &mail_list_item, &search_num, &err)) {
1033                 EM_DEBUG_EXCEPTION("emstorage_search_mails -- Failed [%d]", err);
1034
1035                 goto FINISH_OFF;
1036         }
1037
1038         *mail_list = mail_list_item;
1039         *result_count = search_num;
1040         
1041 FINISH_OFF:     
1042         EM_DEBUG_FUNC_END("err [%d]", err);
1043         return err;
1044 }
1045
1046 EXPORT_API int email_get_mail_by_address(int account_id , const char *mailbox_name, emf_email_address_list_t* addr_list, 
1047                                                                         int start_index, int limit_count, int search_type, const char *search_value, emf_sort_type_t sorting, emf_mail_list_item_t** mail_list,  int* result_count)
1048 {
1049         EM_DEBUG_FUNC_BEGIN();
1050         int err = EMF_ERROR_NONE;
1051
1052         emf_mail_list_item_t* mail_list_item = NULL;
1053         
1054         EM_IF_NULL_RETURN_VALUE(mail_list, EMF_ERROR_INVALID_PARAM);
1055         EM_IF_NULL_RETURN_VALUE(result_count, EMF_ERROR_INVALID_PARAM);
1056
1057         if( account_id < ALL_ACCOUNT) {
1058                 EM_DEBUG_EXCEPTION("Invalid account id param");
1059                 err = EMF_ERROR_INVALID_PARAM ;
1060                 return err;
1061         }
1062
1063         if (!emstorage_get_mail_list(account_id, (char*)mailbox_name, addr_list, EMF_LIST_TYPE_NORMAL, start_index, limit_count, search_type, search_value, sorting, true, &mail_list_item, result_count, &err)) {
1064                 EM_DEBUG_EXCEPTION("emstorage_get_mail_list failed [%d]", err);
1065
1066                 goto FINISH_OFF;
1067         }
1068
1069         *mail_list = mail_list_item;
1070
1071 FINISH_OFF:
1072         EM_DEBUG_FUNC_END("err [%d]", err);
1073         return err;
1074 }
1075
1076 EXPORT_API int email_get_thread_information_by_thread_id(int thread_id, emf_mail_data_t** thread_info)
1077 {
1078         EM_DEBUG_FUNC_BEGIN();
1079         int err = EMF_ERROR_NONE;
1080         emstorage_mail_tbl_t *mail_table_data = NULL;
1081         
1082         EM_IF_NULL_RETURN_VALUE(thread_info, EMF_ERROR_INVALID_PARAM);
1083
1084         if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
1085                 EM_DEBUG_EXCEPTION("emstorage_get_thread_information  failed [%d]", err);
1086                 goto FINISH_OFF;
1087         }
1088
1089         if(!em_convert_mail_tbl_to_mail_data(mail_table_data, 1, thread_info, &err)) {
1090                 EM_DEBUG_EXCEPTION("em_convert_mail_tbl_to_mail_data failed [%d]", err);
1091                 goto FINISH_OFF;
1092         }
1093
1094 FINISH_OFF:     
1095
1096         if(mail_table_data && !emstorage_free_mail(&mail_table_data, 1, &err)) 
1097                 EM_DEBUG_EXCEPTION("emstorage_free_mail failed [%d]", err);
1098
1099         EM_DEBUG_FUNC_END("err [%d]", err);
1100         return err;
1101 }
1102
1103 EXPORT_API int email_get_thread_information_ex(int thread_id, emf_mail_list_item_t** thread_info)
1104 {
1105         EM_DEBUG_FUNC_BEGIN();
1106         int err = EMF_ERROR_NONE;
1107         emstorage_mail_tbl_t *mail_table_data = NULL;
1108         emf_mail_list_item_t *temp_thread_info = NULL;
1109         
1110         EM_IF_NULL_RETURN_VALUE(thread_info, EMF_ERROR_INVALID_PARAM);
1111
1112         if (!emstorage_get_thread_information(thread_id, &mail_table_data , true, &err)) {
1113                 EM_DEBUG_EXCEPTION("emstorage_get_thread_information -- failed [%d]", err);
1114                 goto FINISH_OFF;
1115         }
1116
1117         temp_thread_info = em_malloc(sizeof(emf_mail_list_item_t));
1118
1119         if(!temp_thread_info) {
1120                 EM_DEBUG_EXCEPTION("em_malloc failed");
1121                 err = EMF_ERROR_OUT_OF_MEMORY;
1122                 goto FINISH_OFF;
1123         }
1124
1125         EM_SAFE_STRNCPY(temp_thread_info->mailbox_name       , mail_table_data->mailbox_name, STRING_LENGTH_FOR_DISPLAY);
1126         EM_SAFE_STRNCPY(temp_thread_info->from               , mail_table_data->full_address_from, STRING_LENGTH_FOR_DISPLAY);
1127         EM_SAFE_STRNCPY(temp_thread_info->from_email_address , mail_table_data->email_address_sender, MAX_EMAIL_ADDRESS_LENGTH);
1128         EM_SAFE_STRNCPY(temp_thread_info->recipients         , mail_table_data->email_address_recipient, STRING_LENGTH_FOR_DISPLAY);
1129         EM_SAFE_STRNCPY(temp_thread_info->subject            , mail_table_data->subject, STRING_LENGTH_FOR_DISPLAY);
1130         EM_SAFE_STRNCPY(temp_thread_info->previewBodyText    , mail_table_data->preview_text, MAX_PREVIEW_TEXT_LENGTH);
1131         temp_thread_info->mail_id                            = mail_table_data->mail_id;
1132         temp_thread_info->account_id                         = mail_table_data->account_id;
1133         temp_thread_info->date_time                          = mail_table_data->date_time;
1134         temp_thread_info->is_text_downloaded                 = mail_table_data->body_download_status;
1135         temp_thread_info->flags_seen_field                   = mail_table_data->flags_seen_field;
1136         temp_thread_info->priority                           = mail_table_data->priority;
1137         temp_thread_info->save_status                        = mail_table_data->save_status;
1138         temp_thread_info->is_locked                          = mail_table_data->lock_status;
1139         temp_thread_info->is_report_mail                     = mail_table_data->report_status;
1140         temp_thread_info->has_attachment                     = mail_table_data->attachment_count;
1141         temp_thread_info->has_drm_attachment                 = mail_table_data->DRM_status;
1142         temp_thread_info->thread_id                          = mail_table_data->thread_id;
1143         temp_thread_info->thread_item_count                  = mail_table_data->thread_item_count;
1144         temp_thread_info->is_meeting_request                 = mail_table_data->meeting_request_status;
1145
1146         *thread_info = temp_thread_info;
1147
1148 FINISH_OFF:     
1149
1150         if(mail_table_data)
1151                 emstorage_free_mail(&mail_table_data, 1, NULL);
1152
1153         EM_DEBUG_FUNC_END("err [%d]", err);
1154         return err;
1155 }
1156
1157 EXPORT_API int email_get_mail_data(int input_mail_id, emf_mail_data_t **output_mail_data)
1158 {
1159         EM_DEBUG_FUNC_BEGIN();
1160         int err = EMF_ERROR_NONE;
1161         
1162         if ( ((err = emcore_get_mail_data(input_mail_id, output_mail_data)) != EMF_ERROR_NONE) || !output_mail_data) 
1163                 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);    
1164                 
1165         EM_DEBUG_FUNC_END("err [%d]", err);     
1166         return err;
1167 }
1168
1169
1170 /* -----------------------------------------------------------
1171                                               Mail Flag API
1172     -----------------------------------------------------------*/
1173 EXPORT_API int email_modify_mail_flag(int mail_id, emf_mail_flag_t new_flag, int onserver)
1174 {
1175         EM_DEBUG_FUNC_BEGIN("mail_id[%d], on_server [ %d] ", mail_id, onserver);
1176         
1177         int err = EMF_ERROR_NONE;
1178
1179         int i_flag, sticky = 0;
1180                 
1181         if ( mail_id <= 0 || (onserver != 0 && onserver != 1) ) {
1182                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
1183                 return EMF_ERROR_INVALID_PARAM;                 
1184         }
1185         
1186         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_MAIL_FLAG);
1187
1188         if(!hAPI) {
1189                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1190                 err = EMF_ERROR_NULL_VALUE;             
1191                 goto FINISH_OFF;
1192         }
1193
1194         /* Mail ID */
1195         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1196                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1197                 err = EMF_ERROR_OUT_OF_MEMORY;          
1198                 goto FINISH_OFF;
1199         }
1200
1201         /* new_flag */
1202         if(!em_convert_mail_flag_to_int(new_flag, &i_flag, &err))  {
1203                 EM_DEBUG_EXCEPTION("em_convert_mail_flag_to_int failed ");
1204                 goto FINISH_OFF;
1205         }
1206
1207         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(i_flag), sizeof(int))) {
1208                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1209                 err = EMF_ERROR_OUT_OF_MEMORY;          
1210                 goto FINISH_OFF;
1211         }
1212
1213         sticky = new_flag.sticky;
1214
1215         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(sticky), sizeof(int))) {
1216                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1217                 err = EMF_ERROR_OUT_OF_MEMORY;          
1218                 goto FINISH_OFF;
1219         }
1220         
1221         /* onserver  */
1222         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
1223                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1224                 err = EMF_ERROR_OUT_OF_MEMORY;          
1225                 goto FINISH_OFF;
1226         }
1227         
1228         
1229         /* Execute API */
1230         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1231                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1232                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
1233                 goto FINISH_OFF;
1234         }
1235         
1236         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1237
1238 FINISH_OFF:
1239         if(hAPI)
1240                 emipc_destroy_email_api(hAPI);
1241
1242         EM_DEBUG_FUNC_END("err [%d]", err);
1243         return err;
1244 }
1245
1246
1247
1248
1249 EXPORT_API int email_modify_seen_flag(int *mail_ids, int num, int seen_flag, int onserver)
1250 {
1251         EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num[%d],seen_flag[%d], on_server [ %d]", mail_ids, num, seen_flag, onserver);
1252         EM_DEBUG_FUNC_END("EMF_ERROR_NOT_IMPLEMENTED");
1253         return EMF_ERROR_NOT_IMPLEMENTED;
1254 }
1255
1256 EXPORT_API int email_set_flags_field(int account_id, int *mail_ids, int num, emf_flags_field_type field_type, int value, int onserver)
1257 {
1258         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);
1259         
1260         int err = EMF_ERROR_NONE;
1261
1262                 
1263         EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
1264         if (account_id == 0 || num <= 0 || (onserver != 0 && onserver != 1)) {
1265                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
1266                 return EMF_ERROR_INVALID_PARAM;                 
1267         }
1268         
1269         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SET_FLAGS_FIELD);
1270         
1271         if(!hAPI) {
1272                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1273                 err = EMF_ERROR_NULL_VALUE;             
1274                 goto FINISH_OFF;
1275         }
1276         
1277         /* account_id*/
1278         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&account_id, sizeof(int))) {
1279                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1280                 err = EMF_ERROR_OUT_OF_MEMORY;          
1281                 goto FINISH_OFF;
1282         }
1283
1284         /* Number of mail_ids */
1285         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
1286                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1287                 err = EMF_ERROR_OUT_OF_MEMORY;          
1288                 goto FINISH_OFF;
1289         }
1290         
1291         /* set of mail_ids */
1292         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
1293                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1294                 err = EMF_ERROR_OUT_OF_MEMORY;          
1295                 goto FINISH_OFF;
1296         }
1297         
1298         /* field_type */
1299         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&field_type, sizeof(int))) {
1300                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1301                 err = EMF_ERROR_OUT_OF_MEMORY;          
1302                 goto FINISH_OFF;
1303         }
1304         
1305         /* value */
1306         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&value, sizeof(int))) {
1307                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1308                 err = EMF_ERROR_OUT_OF_MEMORY;          
1309                 goto FINISH_OFF;
1310         }
1311
1312         /* onserver  */
1313         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(onserver), sizeof(int))) {
1314                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1315                 err = EMF_ERROR_OUT_OF_MEMORY;          
1316                 goto FINISH_OFF;
1317         }
1318         
1319         /* Execute API */
1320         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1321                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1322                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
1323                 goto FINISH_OFF;
1324         }
1325         
1326         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1327
1328 FINISH_OFF:
1329         if(hAPI)
1330                 emipc_destroy_email_api(hAPI);
1331
1332         EM_DEBUG_FUNC_END("err [%d]", err);
1333         return err;
1334 }
1335
1336 EXPORT_API int email_modify_extra_mail_flag(int mail_id, emf_extra_flag_t new_flag)
1337 {
1338         EM_DEBUG_FUNC_BEGIN("mail_id[%d]", mail_id);
1339         
1340         int size = 0;
1341         int err = EMF_ERROR_NONE;
1342         char* pMailExtraFlagsStream = NULL;
1343
1344                 
1345         EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
1346
1347         pMailExtraFlagsStream = em_convert_extra_flags_to_byte_stream(new_flag, &size);
1348         
1349         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_MAIL_EXTRA_FLAG);
1350
1351         if(!hAPI) {
1352                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1353                 err = EMF_ERROR_NULL_VALUE;             
1354                 goto FINISH_OFF;
1355         }
1356
1357         /* Mail ID */
1358         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1359                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1360                 err = EMF_ERROR_OUT_OF_MEMORY;          
1361                 goto FINISH_OFF;
1362         }
1363         /*  Flag */
1364         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, pMailExtraFlagsStream, size)) {
1365                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed ");
1366                 err = EMF_ERROR_OUT_OF_MEMORY;          
1367                 goto FINISH_OFF;
1368         }
1369
1370         /* Execute API */
1371         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1372                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1373                 err = EMF_ERROR_IPC_SOCKET_FAILURE;
1374                 goto FINISH_OFF;
1375         } 
1376
1377         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1378
1379 FINISH_OFF:
1380         emipc_destroy_email_api(hAPI);
1381         EM_SAFE_FREE(pMailExtraFlagsStream);
1382
1383         EM_DEBUG_FUNC_END("err [%d]", err);
1384         return err;
1385
1386 }
1387
1388
1389
1390 /* -----------------------------------------------------------
1391                                               Mail Move API
1392     -----------------------------------------------------------*/
1393 EXPORT_API int email_move_mail_to_mailbox(int *mail_ids, int num, emf_mailbox_t* mailbox)
1394 {
1395         EM_DEBUG_FUNC_BEGIN("mail_ids[%p], num [%d], mailbox[%p]",  mail_ids, num, mailbox);
1396         
1397         int size = 0;
1398         char* mailbox_stream =  NULL;
1399         int err = EMF_ERROR_NONE;
1400         HIPC_API hAPI = NULL;
1401
1402
1403         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
1404         EM_IF_NULL_RETURN_VALUE(mail_ids, EMF_ERROR_INVALID_PARAM);
1405         EM_IF_ACCOUNT_ID_NULL(mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
1406         
1407         if (num <= 0)  {
1408                 EM_DEBUG_LOG("num = %d", num);
1409                 err = EMF_ERROR_INVALID_PARAM;
1410                 return err;
1411         }
1412         
1413         hAPI = emipc_create_email_api(_EMAIL_API_MOVE_MAIL);
1414
1415         if(!hAPI) {
1416                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1417                 err = EMF_ERROR_NULL_VALUE;             
1418                 goto FINISH_OFF;
1419         }
1420         
1421         /* Number of mail_ids */
1422         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&num, sizeof(int))) {
1423                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1424                 err = EMF_ERROR_OUT_OF_MEMORY;          
1425                 goto FINISH_OFF;
1426         }
1427         
1428         /* set of mail_ids */
1429         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)mail_ids, num * sizeof(int))) {
1430                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1431                 err = EMF_ERROR_OUT_OF_MEMORY;          
1432                 goto FINISH_OFF;
1433         }
1434         
1435         /* Mailbox */
1436         mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
1437
1438         if(!mailbox_stream) {
1439                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
1440                 err = EMF_ERROR_NULL_VALUE;             
1441                 goto FINISH_OFF;
1442         }
1443
1444         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, mailbox_stream, size)) {
1445                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1446                 err = EMF_ERROR_OUT_OF_MEMORY;          
1447                 goto FINISH_OFF;
1448         }
1449
1450         /* Execute API */
1451         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1452                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1453                 err = EMF_ERROR_IPC_SOCKET_FAILURE;             
1454                 goto FINISH_OFF;
1455         }
1456
1457         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1458
1459 FINISH_OFF:             
1460         EM_SAFE_FREE(mailbox_stream); 
1461
1462         if(hAPI)
1463                 emipc_destroy_email_api(hAPI);
1464
1465         EM_DEBUG_FUNC_END("err [%d]", err);
1466         return err;
1467 }
1468
1469
1470 EXPORT_API int  email_move_all_mails_to_mailbox(emf_mailbox_t* src_mailbox, emf_mailbox_t* new_mailbox)
1471 {
1472         EM_DEBUG_FUNC_BEGIN("src_mailbox[%p] , new_mailbox[%p]",  src_mailbox, new_mailbox);
1473         
1474         int size = 0;
1475         int err = EMF_ERROR_NONE;
1476         char *dest_mailbox_stream = NULL;
1477         char *source_mailbox_stream = NULL;
1478         HIPC_API hAPI = NULL;
1479         
1480
1481         EM_IF_NULL_RETURN_VALUE(src_mailbox, EMF_ERROR_INVALID_PARAM);
1482         EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
1483         EM_IF_ACCOUNT_ID_NULL(new_mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
1484         EM_IF_ACCOUNT_ID_NULL(src_mailbox->account_id, EMF_ERROR_INVALID_PARAM); 
1485         
1486         hAPI = emipc_create_email_api(_EMAIL_API_MOVE_ALL_MAIL);
1487
1488         if(!hAPI) {
1489                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1490                 err = EMF_ERROR_NULL_VALUE;             
1491                 goto FINISH_OFF;
1492         }
1493         
1494         /* Src Mailbox Information */
1495         source_mailbox_stream = em_convert_mailbox_to_byte_stream(src_mailbox, &size);
1496
1497         if(!source_mailbox_stream) {
1498                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
1499                 err = EMF_ERROR_NULL_VALUE;             
1500                 goto FINISH_OFF;
1501         }
1502
1503         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, source_mailbox_stream, size)) {
1504                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1505                 err = EMF_ERROR_OUT_OF_MEMORY;          
1506                 goto FINISH_OFF;
1507         }
1508
1509         size = 0;
1510         
1511         /* Dst Mailbox Information */
1512         dest_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
1513
1514         if(!dest_mailbox_stream) {
1515                 EM_DEBUG_EXCEPTION("em_convert_mailbox_to_byte_stream failed");
1516                 err = EMF_ERROR_NULL_VALUE;             
1517                 goto FINISH_OFF;
1518         }
1519
1520         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, dest_mailbox_stream, size)) {
1521                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1522                 err = EMF_ERROR_OUT_OF_MEMORY;          
1523                 goto FINISH_OFF;
1524         }
1525         
1526         /* Execute API */
1527         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1528                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1529                 err = EMF_ERROR_IPC_SOCKET_FAILURE;             
1530                 goto FINISH_OFF;
1531         }
1532
1533         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1534
1535 FINISH_OFF:
1536         EM_SAFE_FREE(source_mailbox_stream);
1537         EM_SAFE_FREE(dest_mailbox_stream); 
1538
1539         if(hAPI)
1540                 emipc_destroy_email_api(hAPI);
1541         
1542         EM_DEBUG_FUNC_END("err [%d]", err);
1543         return err;
1544 }
1545  
1546
1547
1548 EXPORT_API int email_count_message_with_draft_flag(emf_mailbox_t* mailbox, int* total)
1549 {
1550         EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p]", mailbox, total);
1551         
1552         int err = EMF_ERROR_NONE;
1553         int total_count = 0;
1554                 
1555         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
1556         EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
1557
1558     if (!emstorage_get_mail_count_with_draft_flag(mailbox->account_id,  mailbox->name, &total_count, false, &err)) {
1559                 EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
1560
1561         } else {
1562                 *total = total_count;
1563         }
1564         EM_DEBUG_FUNC_END("err [%d]", err);
1565         return err;
1566 }
1567
1568
1569 EXPORT_API int email_count_message_on_sending(emf_mailbox_t* mailbox, int* total)
1570 {
1571         EM_DEBUG_FUNC_BEGIN("mailbox[%p], total[%p]", mailbox, total);
1572         int err = EMF_ERROR_NONE;
1573         int total_count = 0;
1574         
1575                 
1576         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
1577         EM_IF_NULL_RETURN_VALUE(total, EMF_ERROR_INVALID_PARAM);
1578
1579         if (!emstorage_get_mail_count_on_sending(mailbox->account_id,  mailbox->name, &total_count, false, &err)) {
1580                 EM_DEBUG_EXCEPTION("emstorage_get_mail_count Failed");
1581
1582         } else
1583                 *total = total_count;
1584         EM_DEBUG_FUNC_END("err [%d]", err);
1585         return err;
1586 }
1587
1588 /**
1589  
1590  * @open
1591  * @fn email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
1592  * @brief       Get the Mail Flag information based on the account id and Mail Id.
1593  * 
1594  * @param[in] account_id        Specifies the Account ID
1595  * @param[in] mail_id           Specifies the Mail id for which  Flag details need to be fetched
1596  * @param[in/out] mail_flag     Specifies the Pointer to the structure emf_mail_flag_t.
1597  * @remarks N/A
1598  * @return True on Success, False on Failure.
1599  */
1600 EXPORT_API int email_get_mail_flag(int account_id, int mail_id, emf_mail_flag_t* mail_flag)
1601 {
1602         EM_DEBUG_FUNC_BEGIN();
1603         
1604         int err = EMF_ERROR_NONE;
1605
1606         if (account_id < FIRST_ACCOUNT_ID|| mail_id < 1 || mail_flag == NULL) {
1607                 EM_DEBUG_EXCEPTION("Invalid Param");
1608                 err = EMF_ERROR_INVALID_PARAM ;
1609                 goto FINISH_OFF;
1610         }
1611
1612         /* Fetch the flag Information */
1613         if (!emcore_fetch_flags(account_id, mail_id, mail_flag, &err)) {        
1614                 EM_DEBUG_EXCEPTION("emcore_fetch_flags Failed [%d]", err);
1615                 goto FINISH_OFF;
1616         }
1617 FINISH_OFF:
1618         EM_DEBUG_FUNC_END("err [%d]", err);
1619         return err;
1620
1621 }
1622
1623  
1624 EXPORT_API int email_free_mail_data(emf_mail_data_t** mail_list, int count)
1625 {
1626         EM_DEBUG_FUNC_BEGIN("mail_list[%p], count[%d]", mail_list, count);
1627         int err = EMF_ERROR_NONE;
1628         emcore_free_mail_data(mail_list, count, &err);
1629         EM_DEBUG_FUNC_END("err [%d]", err);     
1630         return err;
1631 }
1632
1633 /* Convert Modified UTF-7 mailbox name to UTF-8 */
1634 /* returns modified UTF-8 Name if success else NULL */
1635
1636 EXPORT_API int email_cancel_send_mail( int mail_id)
1637 {
1638         EM_DEBUG_FUNC_BEGIN("Mail ID [ %d]", mail_id);
1639         EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
1640         
1641         int err = EMF_ERROR_NONE;
1642         int account_id = 0;
1643         emf_mail_data_t* mail_data = NULL;
1644
1645         HIPC_API hAPI = NULL;
1646         
1647         
1648         if ((err = emcore_get_mail_data(mail_id, &mail_data)) != EMF_ERROR_NONE)  {
1649                 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed [%d]", err);
1650                 goto FINISH_OFF;
1651         }
1652
1653         if (!mail_data) {
1654                 EM_DEBUG_EXCEPTION("mail_data is null");
1655                 err = EMF_ERROR_NULL_VALUE;             
1656                 goto FINISH_OFF;
1657         }
1658
1659         account_id = mail_data->account_id;
1660
1661         hAPI = emipc_create_email_api(_EMAIL_API_SEND_MAIL_CANCEL_JOB);
1662
1663         if(!hAPI) {
1664                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1665                 err = EMF_ERROR_NULL_VALUE;             
1666                 goto FINISH_OFF;
1667         }
1668
1669         /* Account_id */
1670         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int))) {
1671                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1672                 err = EMF_ERROR_OUT_OF_MEMORY;          
1673                 goto FINISH_OFF;
1674         }
1675
1676         /* Mail ID */
1677         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1678                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1679                 err = EMF_ERROR_OUT_OF_MEMORY;          
1680                 goto FINISH_OFF;
1681         }
1682
1683         /* Execute API */
1684         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1685                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1686                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
1687                 goto FINISH_OFF;
1688         }
1689         
1690         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1691
1692 FINISH_OFF:
1693         if(hAPI)
1694                 emipc_destroy_email_api(hAPI);
1695
1696         if  ( !emcore_free_mail_data(&mail_data, 1, &err))
1697                 EM_DEBUG_EXCEPTION("emcore_free_mail_data Failed [%d ] ", err);
1698
1699         EM_DEBUG_FUNC_END("err [%d]", err);
1700         return err;
1701
1702 }
1703 /**
1704   * EmfSendCancel - Callback function for cm popup. We set the status as EMF_MAIL_STATUS_NONE 
1705   *
1706   **/
1707
1708
1709 EXPORT_API int email_retry_send_mail( int mail_id, int timeout_in_sec)
1710 {
1711         EM_DEBUG_FUNC_BEGIN();
1712         
1713         int err = EMF_ERROR_NONE;
1714
1715
1716         EM_IF_NULL_RETURN_VALUE(mail_id, EMF_ERROR_INVALID_PARAM);
1717         if( timeout_in_sec < 0 )  {
1718                 EM_DEBUG_EXCEPTION("Invalid timeout_in_sec");
1719                 err = EMF_ERROR_INVALID_PARAM;
1720                 return err;
1721         }
1722         
1723         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_SEND_RETRY);
1724
1725         if(!hAPI) {
1726                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
1727                 err = EMF_ERROR_NULL_VALUE;             
1728                 goto FINISH_OFF;
1729         }
1730
1731         /* Mail ID */
1732         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(mail_id), sizeof(int))) {
1733                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1734                 err = EMF_ERROR_OUT_OF_MEMORY;          
1735                 goto FINISH_OFF;
1736         }
1737
1738         /* timeout */
1739         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, &(timeout_in_sec), sizeof(int))) {
1740                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
1741                 err = EMF_ERROR_OUT_OF_MEMORY;          
1742                 goto FINISH_OFF;
1743         }
1744         
1745         /* Execute API */
1746         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
1747                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
1748                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
1749                 goto FINISH_OFF;
1750         }
1751         
1752         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
1753
1754 FINISH_OFF:
1755         if(hAPI)
1756                 emipc_destroy_email_api(hAPI);
1757
1758         EM_DEBUG_FUNC_END("err [%d]", err);
1759         return err;
1760
1761  }
1762
1763 EXPORT_API int email_get_mailbox_name_by_mail_id(int mail_id, char **pMailbox_name)
1764 {
1765         EM_DEBUG_FUNC_BEGIN();
1766         
1767         int err = EMF_ERROR_NONE;
1768         char* mailbox_name = NULL;
1769         emstorage_mail_tbl_t* mail_table_data = NULL;
1770         
1771         if(mail_id <= 0) {
1772                 EM_DEBUG_EXCEPTION("mail_id is not valid");
1773                 err= EMF_ERROR_INVALID_PARAM;
1774                 goto FINISH_OFF;
1775         }       
1776         EM_IF_NULL_RETURN_VALUE(pMailbox_name, EMF_ERROR_INVALID_PARAM);
1777         
1778         if(!emstorage_get_mail_by_id(mail_id, &mail_table_data, true, &err)) {
1779                 EM_DEBUG_EXCEPTION("Failed to get mail by mail_id [%d]", err);
1780
1781                 goto FINISH_OFF;
1782         }
1783
1784         if(mail_table_data->mailbox_name)
1785                 mailbox_name = strdup(mail_table_data->mailbox_name);
1786         
1787         *pMailbox_name = mailbox_name;
1788
1789 FINISH_OFF:
1790         if(mail_table_data) {
1791                 emstorage_free_mail(&mail_table_data, 1, &err); 
1792
1793         }
1794         EM_DEBUG_FUNC_END("err [%d]", err);
1795         return err;
1796 }
1797
1798
1799 EXPORT_API int email_get_latest_unread_mail_id(int account_id, int *pMailID)
1800 {
1801         EM_DEBUG_FUNC_BEGIN();
1802         
1803         int err = EMF_ERROR_NONE;
1804
1805         if( (!pMailID) ||(account_id <= 0 &&  account_id != -1)) {              
1806                 err = EMF_ERROR_INVALID_PARAM;
1807                 return err;
1808         }
1809         if(!emstorage_get_latest_unread_mailid(account_id,pMailID, &err)) {
1810                 EM_DEBUG_LOG("emstorage_get_latest_unread_mailid - failed");
1811
1812         }
1813         EM_DEBUG_FUNC_END("err [%d]", err);
1814         return err;
1815 }
1816
1817 EXPORT_API int email_get_max_mail_count(int *Count)
1818 {
1819         EM_DEBUG_FUNC_BEGIN();
1820         int err = EMF_ERROR_NONE;
1821         EM_IF_NULL_RETURN_VALUE(Count, EMF_ERROR_INVALID_PARAM);
1822         *Count = emstorage_get_max_mail_count();
1823         EM_DEBUG_FUNC_END("err [%d]", err);
1824         return err;
1825 }
1826
1827
1828
1829 /* for setting application,disk usage of email in KB */
1830 EXPORT_API int email_get_disk_space_usage(unsigned long *total_size)
1831 {
1832         EM_DEBUG_FUNC_BEGIN("total_size[%p]", total_size);
1833         int err = EMF_ERROR_NONE;
1834
1835         EM_IF_NULL_RETURN_VALUE(total_size, EMF_ERROR_INVALID_PARAM);
1836
1837         if (!emstorage_mail_get_total_diskspace_usage(total_size,true,&err))  {
1838                 EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage failed [%d]", err);
1839
1840                 goto FINISH_OFF;
1841         }
1842 FINISH_OFF :    
1843         EM_DEBUG_FUNC_END("err [%d]", err);
1844         return err;
1845 }
1846
1847 EXPORT_API int email_get_recipients_list(int account_id, const char *mailbox_name, emf_sender_list_t **recipients_list)
1848 {
1849         EM_DEBUG_FUNC_BEGIN("recipients_list[%p]",  recipients_list);
1850
1851         int number_of_mails, index;
1852         int number_of_recipients;
1853         int ret=0, err = 0;
1854
1855         emf_sender_list_t *temp_recipients_list = NULL;
1856         emf_sender_list_t *p_recipients_list = NULL;
1857         GList *addr_list = NULL, *temp_addr_list = NULL;
1858         emstorage_mail_tbl_t *mail_table_data = NULL;
1859
1860         if (!emstorage_get_mails(account_id, (char*)mailbox_name, NULL, EMF_LIST_TYPE_NORMAL, -1, -1, EMF_SORT_SENDER_HIGH, true, &mail_table_data, &number_of_mails, &err)) {
1861                 EM_DEBUG_EXCEPTION("emstorage_get_mails failed");
1862
1863                 goto FINISH_OFF;
1864         }
1865
1866         for (index = 0; index < number_of_mails; index++) {
1867                 addr_list = emcore_get_recipients_list(addr_list, mail_table_data[index].full_address_to, &err);
1868                 addr_list = emcore_get_recipients_list(addr_list, mail_table_data[index].full_address_cc, &err);
1869                 addr_list = emcore_get_recipients_list(addr_list, mail_table_data[index].full_address_bcc, &err);
1870         }
1871
1872         number_of_recipients = g_list_length(addr_list);
1873
1874         p_recipients_list = (emf_sender_list_t *)malloc(sizeof(emf_sender_list_t) * number_of_recipients);
1875         if (p_recipients_list == NULL) {
1876                 EM_DEBUG_EXCEPTION("malloc for emf_sender_list_t failed...");
1877                 err = EMF_ERROR_OUT_OF_MEMORY;
1878                 ret = err;
1879                 goto FINISH_OFF;
1880         }       
1881         memset(p_recipients_list, 0x00, sizeof(emf_sender_list_t) * number_of_recipients);
1882         
1883         temp_addr_list = g_list_first(addr_list);
1884         index = 0;
1885         while (temp_addr_list != NULL) {
1886                 temp_recipients_list = (emf_sender_list_t *)temp_addr_list->data;
1887                 p_recipients_list[index].address = temp_recipients_list->address;
1888                 p_recipients_list[index].display_name = temp_recipients_list->display_name;
1889                 p_recipients_list[index].total_count = temp_recipients_list->total_count + 1;
1890                 EM_DEBUG_LOG("address[%s], display_name[%s], total_count[%d]", p_recipients_list[index].address, p_recipients_list[index].display_name, p_recipients_list[index].total_count);
1891                 temp_addr_list = g_list_next(temp_addr_list);
1892                 index++;
1893         }
1894
1895         ret = true;     
1896 FINISH_OFF:
1897         if (ret == true && recipients_list)
1898                 *recipients_list = p_recipients_list; else if (p_recipients_list != NULL) {
1899                 email_free_sender_list(&p_recipients_list, number_of_recipients);
1900         }
1901
1902         EM_DEBUG_FUNC_END();
1903         return ret;
1904 }
1905
1906 EXPORT_API int email_get_sender_list(int account_id, const char *mailbox_name, int search_type, const char *search_value, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
1907 {
1908         EM_DEBUG_FUNC_BEGIN("sender_list[%p],sender_count[%p], sorting[%d]",  sender_list, sender_count, sorting);
1909
1910         int err = EMF_ERROR_NONE;
1911
1912         emf_sender_list_t *temp_sender_list = NULL;
1913
1914         EM_IF_NULL_RETURN_VALUE(sender_list, EMF_ERROR_INVALID_PARAM);
1915         EM_IF_NULL_RETURN_VALUE(sender_count, EMF_ERROR_INVALID_PARAM);
1916         if( account_id < ALL_ACCOUNT) {
1917                 EM_DEBUG_EXCEPTION(" Invalid Account Id Param ");
1918                 err = EMF_ERROR_INVALID_PARAM ;
1919                 return err;
1920         }
1921         
1922         if ( !emstorage_get_sender_list(account_id, mailbox_name, search_type, search_value, sorting, &temp_sender_list, sender_count, &err) ) { 
1923                 EM_DEBUG_EXCEPTION("emstorage_get_sender_list failed [%d]", err);
1924
1925                 goto FINISH_OFF;
1926         }
1927
1928         if ( sender_list )
1929                 *sender_list = temp_sender_list;
1930
1931 FINISH_OFF:
1932         EM_DEBUG_FUNC_END("err [%d]", err);
1933         return err;
1934 }
1935
1936 EXPORT_API int email_get_sender_list_ex(int account_id, const char *mailbox_name, int start_index, int limit_count, emf_sort_type_t sorting, emf_sender_list_t** sender_list, int *sender_count)
1937 {
1938         return EMF_ERROR_NONE;
1939 }
1940
1941 EXPORT_API int email_free_sender_list(emf_sender_list_t **sender_list, int count)
1942 {
1943         EM_DEBUG_FUNC_BEGIN("sender_list[%p], count[%d]", sender_list, count);
1944
1945         int err = EMF_ERROR_NONE;
1946         
1947         if (count > 0)  {
1948                 if (!sender_list || !*sender_list)  {
1949                         EM_DEBUG_EXCEPTION("sender_list[%p], count[%d]", sender_list, count);                   
1950                         err = EMF_ERROR_INVALID_PARAM;
1951                         return err;
1952                 }
1953                 
1954                 emf_sender_list_t* p = *sender_list;
1955                 int i = 0;
1956                 
1957                 for (; i < count; i++)  {
1958                         EM_SAFE_FREE(p[i].address);
1959                         EM_SAFE_FREE(p[i].display_name);
1960                 }
1961                 
1962                 EM_SAFE_FREE(p); 
1963                 *sender_list = NULL;
1964         }       
1965         EM_DEBUG_FUNC_END("err [%d]", err);
1966         return err;
1967 }
1968
1969 EXPORT_API int email_get_address_info_list(int mail_id, emf_address_info_list_t** address_info_list)
1970 {
1971         EM_DEBUG_FUNC_BEGIN("mail_id[%d], address_info_list[%p]", mail_id, address_info_list);
1972
1973         int err = EMF_ERROR_NONE;
1974
1975         emf_address_info_list_t *temp_address_info_list = NULL;
1976
1977         EM_IF_NULL_RETURN_VALUE(address_info_list, EMF_ERROR_INVALID_PARAM);
1978         if( mail_id <= 0) {
1979                 EM_DEBUG_EXCEPTION("EMF_ERROR_INVALID_PARAM");
1980                 err = EMF_ERROR_INVALID_PARAM ;
1981                 return err;
1982         }
1983         
1984         if ( !emcore_get_mail_address_info_list(mail_id, &temp_address_info_list, &err) ) {
1985                 EM_DEBUG_EXCEPTION("emcore_get_mail_address_info_list failed [%d]", err);
1986
1987                 goto FINISH_OFF;
1988         }
1989
1990         if ( address_info_list ) {
1991                 *address_info_list = temp_address_info_list;
1992                 temp_address_info_list = NULL;
1993         }
1994
1995 FINISH_OFF:
1996         if ( temp_address_info_list )
1997                 emstorage_free_address_info_list(&temp_address_info_list);
1998         EM_DEBUG_FUNC_END("err [%d]", err);
1999         return err;
2000 }
2001
2002 EXPORT_API int email_free_address_info_list(emf_address_info_list_t **address_info_list)
2003 {
2004         EM_DEBUG_FUNC_BEGIN("address_info_list[%p]", address_info_list);
2005
2006         int err = EMF_ERROR_NONE;
2007
2008         if ( (err = emstorage_free_address_info_list(address_info_list)) != EMF_ERROR_NONE ) {
2009                 EM_DEBUG_EXCEPTION("address_info_list[%p] free failed.", address_info_list);
2010         }
2011         EM_DEBUG_FUNC_END("err [%d]", err);
2012         return err;
2013 }
2014
2015 EXPORT_API int email_get_structure(const char*encoded_string, void **struct_var, emf_convert_struct_type_e type)
2016 {
2017         EM_DEBUG_FUNC_BEGIN("encoded_string[%s], struct_var[%p], type[%d]", encoded_string, struct_var, type);
2018
2019         int err = EMF_ERROR_NONE;
2020         void * temp_struct = NULL;
2021
2022         EM_IF_NULL_RETURN_VALUE(encoded_string, EMF_ERROR_INVALID_PARAM);
2023         EM_IF_NULL_RETURN_VALUE(struct_var, EMF_ERROR_INVALID_PARAM);
2024
2025         if ( (err = emcore_convert_string_to_structure((char*)encoded_string, &temp_struct, type)) != EMF_ERROR_NONE )  {
2026                 EM_DEBUG_EXCEPTION("emcore_convert_string_to_structure failed[%d]", err);
2027                 goto FINISH_OFF;
2028         }
2029
2030         if ( struct_var )
2031                 *struct_var = temp_struct;
2032
2033 FINISH_OFF:
2034         EM_DEBUG_FUNC_END("err [%d]", err);
2035         return err;
2036 }
2037
2038 EXPORT_API int email_get_meeting_request(int mail_id, emf_meeting_request_t **meeting_req)
2039 {
2040         EM_DEBUG_FUNC_BEGIN("mail_id[%d],meeting_req[%p]",  mail_id, meeting_req);
2041
2042         int err = EMF_ERROR_NONE;
2043
2044         emf_meeting_request_t *temp_meeting_req = NULL;
2045
2046         EM_IF_NULL_RETURN_VALUE(meeting_req, EMF_ERROR_INVALID_PARAM);
2047         if( mail_id <= 0 ) {
2048                 EM_DEBUG_EXCEPTION(" Invalid Mail Id Param ");
2049                 err = EMF_ERROR_INVALID_PARAM ;
2050                 return err;
2051         }
2052         
2053         if ( !emstorage_get_meeting_request(mail_id, &temp_meeting_req, 1, &err) ) {
2054                 EM_DEBUG_EXCEPTION("emstorage_get_meeting_request -- Failed [%d]", err);
2055
2056                 goto FINISH_OFF;
2057         }
2058
2059         if ( meeting_req )
2060                 *meeting_req = temp_meeting_req;
2061
2062 FINISH_OFF:
2063         EM_DEBUG_FUNC_END("err [%d]", err);
2064         return err;
2065 }
2066
2067 EXPORT_API int email_free_meeting_request(emf_meeting_request_t** meeting_req, int count)
2068 {
2069         EM_DEBUG_FUNC_BEGIN("meeting_req[%p], count[%d]", meeting_req, count);
2070
2071         int err = EMF_ERROR_NONE;
2072
2073         emstorage_free_meeting_request(meeting_req, count, &err);
2074
2075         EM_DEBUG_FUNC_END("err [%d]", err);
2076         return err;
2077 }
2078
2079 EXPORT_API int email_move_thread_to_mailbox(int thread_id, char *target_mailbox_name, int move_always_flag)
2080 {
2081         EM_DEBUG_FUNC_BEGIN("thread_id[%d], target_mailbox_name[%p], move_always_flag[%d]", thread_id, target_mailbox_name, move_always_flag);
2082         int err = EMF_ERROR_NONE;
2083         
2084
2085         EM_IF_NULL_RETURN_VALUE(target_mailbox_name, EMF_ERROR_INVALID_PARAM);
2086         
2087         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MOVE_THREAD_TO_MAILBOX);
2088
2089         if(!hAPI) {
2090                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
2091                 err = EMF_ERROR_NULL_VALUE;             
2092                 goto FINISH_OFF;
2093         }
2094
2095         /* thread_id */
2096         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
2097                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2098                 err = EMF_ERROR_OUT_OF_MEMORY;          
2099                 goto FINISH_OFF;
2100         }
2101         
2102         /* target mailbox information */
2103         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, target_mailbox_name, strlen(target_mailbox_name))){
2104                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2105                 err = EMF_ERROR_OUT_OF_MEMORY;          
2106                 goto FINISH_OFF;
2107         }
2108
2109         /* move_always_flag */
2110         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&move_always_flag, sizeof(int))){
2111                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2112                 err = EMF_ERROR_OUT_OF_MEMORY;          
2113                 goto FINISH_OFF;
2114         }
2115         
2116         /* Execute API */
2117         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
2118                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
2119                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
2120                 goto FINISH_OFF;
2121         }
2122         
2123         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
2124
2125 FINISH_OFF:
2126         if(hAPI)
2127                 emipc_destroy_email_api(hAPI);
2128
2129         EM_DEBUG_FUNC_END("err [%d]", err);
2130         return err;
2131 }
2132
2133 EXPORT_API int email_delete_thread(int thread_id, int delete_always_flag)
2134 {
2135         EM_DEBUG_FUNC_BEGIN("thread_id[%d], delete_always_flag[%d]", thread_id, delete_always_flag);
2136         int err = EMF_ERROR_NONE;
2137
2138         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_THREAD);
2139
2140         if(!hAPI) {
2141                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
2142                 err = EMF_ERROR_NULL_VALUE;             
2143                 goto FINISH_OFF;
2144         }
2145
2146         /* thread_id */
2147         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))){
2148                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2149                 err = EMF_ERROR_OUT_OF_MEMORY;          
2150                 goto FINISH_OFF;
2151         }
2152
2153         /* delete_always_flag */
2154         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&delete_always_flag, sizeof(int))){
2155                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2156                 err = EMF_ERROR_OUT_OF_MEMORY;          
2157                 goto FINISH_OFF;
2158         }
2159         
2160         /* Execute API */
2161         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
2162                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
2163                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
2164                 goto FINISH_OFF;
2165         }
2166         
2167         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
2168
2169 FINISH_OFF:
2170         if(hAPI)
2171                 emipc_destroy_email_api(hAPI);
2172
2173         EM_DEBUG_FUNC_END("err [%d]", err);
2174         return err;
2175 }
2176
2177 EXPORT_API int email_modify_seen_flag_of_thread(int thread_id, int seen_flag, int on_server)
2178 {
2179         EM_DEBUG_FUNC_BEGIN("thread_id[%d], seen_flag[%d], on_server[%d]", thread_id, seen_flag, on_server);
2180         int err = EMF_ERROR_NONE;
2181         HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_MODIFY_SEEN_FLAG_OF_THREAD);
2182
2183         if(!hAPI) {
2184                 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
2185                 err = EMF_ERROR_NULL_VALUE;             
2186                 goto FINISH_OFF;
2187         }
2188
2189         /* thread_id */
2190         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&thread_id, sizeof(int))) {
2191                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2192                 err = EMF_ERROR_OUT_OF_MEMORY;          
2193                 goto FINISH_OFF;
2194         }
2195
2196         /* seen_flag */
2197         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&seen_flag, sizeof(int))) {
2198                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2199                 err = EMF_ERROR_OUT_OF_MEMORY;          
2200                 goto FINISH_OFF;
2201         }
2202
2203         /* on_server */
2204         if(!emipc_add_parameter(hAPI, ePARAMETER_IN, (char*)&on_server, sizeof(int))) {
2205                 EM_DEBUG_EXCEPTION("emipc_add_parameter failed");
2206                 err = EMF_ERROR_OUT_OF_MEMORY;          
2207                 goto FINISH_OFF;
2208         }
2209         
2210         /* Execute API */
2211         if(emipc_execute_proxy_api(hAPI) != EMF_ERROR_NONE) {
2212                 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
2213                 err = EMF_ERROR_IPC_SOCKET_FAILURE;     
2214                 goto FINISH_OFF;
2215         }
2216         
2217         emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
2218
2219 FINISH_OFF:
2220         if(hAPI)
2221                 emipc_destroy_email_api(hAPI);
2222         EM_DEBUG_FUNC_END("err [%d]", err);
2223         return err;
2224 }
2225