tizen beta release
[framework/messaging/email-service.git] / MAPI / Emf_Mapi_Mailbox.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 Engine.
28  * @file                Emf_Mapi_Folder.c
29  * @brief               This file contains the data structures and interfaces of mailbox related Functionality provided by 
30  *                      Email Engine . 
31  */
32  
33 #include <Emf_Mapi.h>
34 #include "string.h"
35 #include "Msg_Convert.h"
36 #include "em-storage.h"
37 #include "ipc-library.h"
38 #include "db-util.h"
39
40 /* API - Create a mailbox */
41
42 EXPORT_API int email_add_mailbox(emf_mailbox_t* new_mailbox, int on_server, unsigned* handle)
43 {
44         EM_DEBUG_FUNC_BEGIN();
45         
46         char* local_mailbox_stream = NULL;
47         int size = 0;
48         int err = EMF_ERROR_NONE;
49         EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
50
51         HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_ADD_MAILBOX);
52
53         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
54         
55         local_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
56
57         EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
58
59         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
60                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
61         EM_SAFE_FREE(local_mailbox_stream); 
62
63         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int)))
64                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
65         
66         if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
67                 EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
68                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
69         }
70
71         err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
72         EM_DEBUG_LOG(" >>>>> error VALUE [%d]", err);
73
74         if(handle) {
75                 *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
76                 EM_DEBUG_LOG(" >>>>> Handle [%d]", *handle);
77         }       
78         
79
80         ipcEmailAPI_Destroy(hAPI);
81         hAPI = NULL;
82         EM_DEBUG_FUNC_END("err [%d]", err);
83         return err;
84 }
85
86
87 /* API - Delete a mailbox */
88
89 EXPORT_API int email_delete_mailbox(emf_mailbox_t* mailbox, int on_server,  unsigned* handle)
90 {
91         EM_DEBUG_FUNC_BEGIN("mailbox[%p]", mailbox);
92         
93         char* local_mailbox_stream = NULL;
94         int err = EMF_ERROR_NONE;
95         int size = 0;
96         
97         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);
98         EM_IF_NULL_RETURN_VALUE(mailbox->account_id, EMF_ERROR_INVALID_PARAM)   ;
99
100         HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_DELETE_MAILBOX);
101
102         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
103
104         local_mailbox_stream = em_convert_mailbox_to_byte_stream(mailbox, &size);
105         
106         EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
107
108         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
109                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
110         EM_SAFE_FREE(local_mailbox_stream);
111         
112         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int)))
113                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
114
115
116         if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
117                 EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
118                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
119         }
120
121         err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
122         EM_DEBUG_LOG("error VALUE [%d]", err);
123
124         if(handle) {
125                 *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
126                 EM_DEBUG_LOG("Handle [%d]", handle);
127         }       
128
129         ipcEmailAPI_Destroy(hAPI);
130         hAPI = NULL;
131         EM_DEBUG_FUNC_END("err [%d]", err);
132         return err;
133 }
134
135 /* API - Update a mailbox */
136
137
138 EXPORT_API int email_update_mailbox(emf_mailbox_t* old_mailbox, emf_mailbox_t* new_mailbox)
139 {
140         EM_DEBUG_FUNC_BEGIN();
141         
142         char* local_mailbox_stream = NULL;
143         int err = EMF_ERROR_NONE;       
144         int size = 0;
145         int on_server = 0;
146         EM_DEBUG_LOG(" old_mailbox[%p], new_mailbox[%p]", old_mailbox, new_mailbox);
147
148         EM_IF_NULL_RETURN_VALUE(old_mailbox, EMF_ERROR_INVALID_PARAM);
149         EM_IF_NULL_RETURN_VALUE(old_mailbox->account_id, EMF_ERROR_INVALID_PARAM);
150         EM_IF_NULL_RETURN_VALUE(new_mailbox, EMF_ERROR_INVALID_PARAM);
151         EM_IF_ACCOUNT_ID_NULL(new_mailbox->account_id, EMF_ERROR_INVALID_PARAM);
152         
153         HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_UPDATE_MAILBOX);  
154
155         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
156
157
158         local_mailbox_stream = em_convert_mailbox_to_byte_stream(old_mailbox, &size);
159
160         EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
161                 
162         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
163                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
164         EM_SAFE_FREE(local_mailbox_stream); 
165
166         local_mailbox_stream = em_convert_mailbox_to_byte_stream(new_mailbox, &size);
167
168         EM_PROXY_IF_NULL_RETURN_VALUE(local_mailbox_stream, hAPI, EMF_ERROR_NULL_VALUE);
169
170         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, local_mailbox_stream, size))
171                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
172         EM_SAFE_FREE(local_mailbox_stream); 
173
174         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &on_server, sizeof(int)))
175                 EM_DEBUG_EXCEPTION("ipcEmailAPI_AddParameter failed");
176         
177         if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
178                 EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
179                 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
180         } else {
181                 err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
182                         
183                 EM_DEBUG_LOG("error VALUE [%d]", err);
184                 ipcEmailAPI_Destroy(hAPI);
185                 hAPI = NULL;
186         }
187         EM_DEBUG_FUNC_END("err [%d]", err);
188         return err;
189 }
190
191
192 EXPORT_API int email_get_sync_mailbox_list(int account_id, emf_mailbox_t** mailbox_list, int* count)
193 {
194         EM_DEBUG_FUNC_BEGIN();
195         int counter = 0;
196         emf_mailbox_tbl_t* mailbox = NULL; 
197         int err = EMF_ERROR_NONE ;
198         
199         EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
200         EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
201         EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
202
203         if (!em_storage_get_mailbox(account_id, 0, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &counter, &mailbox, true, &err)) {           /* TODO: confirm me */
204                 EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
205
206                 err = em_storage_get_emf_error_from_em_storage_error(err);
207                 goto FINISH_OFF;
208         } else
209                 err = EMF_ERROR_NONE;
210         
211         if (counter > 0)  {
212                 if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * counter)))  {
213                         EM_DEBUG_EXCEPTION("malloc failed...");
214                         err= EMF_ERROR_OUT_OF_MEMORY;
215                         goto FINISH_OFF;
216                 }
217         } else
218                 *mailbox_list = NULL;
219         
220         *count = counter;
221         
222         FINISH_OFF:
223         if (mailbox != NULL)
224                 em_storage_free_mailbox(&mailbox, counter, NULL);
225         EM_DEBUG_FUNC_END("err [%d]", err);
226         return err;
227 }
228
229
230 EXPORT_API int email_get_mailbox_list(int account_id, int mailbox_sync_type, emf_mailbox_t** mailbox_list, int* count)
231 {
232         EM_DEBUG_FUNC_BEGIN();  
233
234         int mailbox_count = 0;
235         emf_mailbox_tbl_t* mailbox_tbl_list = NULL; 
236         int err =EMF_ERROR_NONE;
237         int i;
238         
239         EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
240         EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
241         EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
242
243         if (!em_storage_get_mailbox(account_id, mailbox_sync_type, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err))  {   
244                 EM_DEBUG_EXCEPTION("em_storage_get_mailbox failed [%d]", err);
245                 err = em_storage_get_emf_error_from_em_storage_error(err);
246                 goto FINISH_OFF;
247         } else
248                 err = EMF_ERROR_NONE;
249         
250         if (mailbox_count > 0)  {
251                 if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * mailbox_count)))  {
252                         EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
253                         err= EMF_ERROR_OUT_OF_MEMORY;
254                         goto FINISH_OFF;
255                 }
256
257                 for (i = 0; i < mailbox_count; i++)  {
258                         (*mailbox_list)[i].mailbox_id = mailbox_tbl_list[i].mailbox_id;
259                         (*mailbox_list)[i].account_id = account_id;
260                         (*mailbox_list)[i].name = mailbox_tbl_list[i].mailbox_name; 
261                         mailbox_tbl_list[i].mailbox_name = NULL;
262                         (*mailbox_list)[i].alias = mailbox_tbl_list[i].alias; 
263                         mailbox_tbl_list[i].alias = NULL;
264                         (*mailbox_list)[i].local = mailbox_tbl_list[i].local_yn;
265                         (*mailbox_list)[i].mailbox_type = mailbox_tbl_list[i].mailbox_type;
266                         (*mailbox_list)[i].synchronous = mailbox_tbl_list[i].sync_with_server_yn;
267                         (*mailbox_list)[i].unread_count = mailbox_tbl_list[i].unread_count;
268                         (*mailbox_list)[i].total_mail_count_on_local = mailbox_tbl_list[i].total_mail_count_on_local;
269                         (*mailbox_list)[i].total_mail_count_on_server = mailbox_tbl_list[i].total_mail_count_on_server;
270                         (*mailbox_list)[i].has_archived_mails = mailbox_tbl_list[i].has_archived_mails;
271                         (*mailbox_list)[i].mail_slot_size = mailbox_tbl_list[i].mail_slot_size;
272                 }
273         } else
274                 *mailbox_list = NULL;
275         
276         *count = mailbox_count;
277
278 FINISH_OFF:
279         if (mailbox_tbl_list != NULL)
280                 em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
281
282         EM_DEBUG_FUNC_END("err [%d]", err);
283         return err;
284 }
285
286
287
288 EXPORT_API int email_get_mailbox_list_ex(int account_id, int mailbox_sync_type, int with_count, emf_mailbox_t** mailbox_list, int* count)
289 {
290         EM_DEBUG_FUNC_BEGIN();  
291
292         int mailbox_count = 0;
293         emf_mailbox_tbl_t* mailbox_tbl_list = NULL; 
294         int err =EMF_ERROR_NONE;
295         int i;
296         
297         EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
298         EM_IF_ACCOUNT_ID_NULL(account_id, EMF_ERROR_INVALID_PARAM);
299         EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
300
301         if (!em_storage_get_mailbox_ex(account_id, mailbox_sync_type, with_count, &mailbox_count, &mailbox_tbl_list, true, &err))  {    
302                 EM_DEBUG_EXCEPTION("em_storage_get_mailbox_ex failed [%d]", err);
303                 err = em_storage_get_emf_error_from_em_storage_error(err);
304                 goto FINISH_OFF;
305         } else
306                 err = EMF_ERROR_NONE;
307         
308         if (mailbox_count > 0)  {
309                 if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * mailbox_count)))  {
310                         EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
311                         err= EMF_ERROR_OUT_OF_MEMORY;
312                         goto FINISH_OFF;
313                 }
314
315                 for (i = 0; i < mailbox_count; i++)  {
316                         (*mailbox_list)[i].mailbox_id = mailbox_tbl_list[i].mailbox_id;
317                         (*mailbox_list)[i].account_id = account_id;
318                         (*mailbox_list)[i].name = mailbox_tbl_list[i].mailbox_name; 
319                         mailbox_tbl_list[i].mailbox_name = NULL;
320                         (*mailbox_list)[i].alias = mailbox_tbl_list[i].alias; 
321                         mailbox_tbl_list[i].alias = NULL;
322                         (*mailbox_list)[i].local = mailbox_tbl_list[i].local_yn;
323                         (*mailbox_list)[i].mailbox_type = mailbox_tbl_list[i].mailbox_type;
324                         (*mailbox_list)[i].synchronous = mailbox_tbl_list[i].sync_with_server_yn;
325                         (*mailbox_list)[i].unread_count = mailbox_tbl_list[i].unread_count;
326                         (*mailbox_list)[i].total_mail_count_on_local = mailbox_tbl_list[i].total_mail_count_on_local;
327                         (*mailbox_list)[i].total_mail_count_on_server = mailbox_tbl_list[i].total_mail_count_on_server;
328                         (*mailbox_list)[i].has_archived_mails = mailbox_tbl_list[i].has_archived_mails;
329                         (*mailbox_list)[i].mail_slot_size = mailbox_tbl_list[i].mail_slot_size;
330                 }
331         } else
332                 *mailbox_list = NULL;
333
334         if ( count )    
335                 *count = mailbox_count;
336
337 FINISH_OFF:
338         if (mailbox_tbl_list != NULL)
339                 em_storage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
340
341         EM_DEBUG_FUNC_END("err [%d]", err);
342         return err;
343 }
344
345
346 EXPORT_API int email_get_mailbox_by_name(int account_id, const char *pMailboxName, emf_mailbox_t **pMailbox)
347 {
348         EM_DEBUG_FUNC_BEGIN();
349         
350         int err = EMF_ERROR_NONE;
351         emf_mailbox_t* curr_mailbox = NULL;
352         emf_mailbox_tbl_t* local_mailbox = NULL;
353
354         EM_IF_NULL_RETURN_VALUE(pMailbox, EMF_ERROR_INVALID_PARAM);
355         if(!pMailboxName)
356                 return EMF_ERROR_INVALID_PARAM; 
357         
358         if (!em_storage_get_mailbox_by_name(account_id, -1, (char*)pMailboxName, &local_mailbox, true, &err))  /* Warning removal changes  */ {
359                 if (err == EM_STORAGE_ERROR_MAILBOX_NOT_FOUND)
360                         err = EMF_ERROR_MAILBOX_NOT_FOUND; else if (err == EM_STORAGE_ERROR_INVALID_PARAM)
361                         err = EMF_ERROR_INVALID_PARAM; else if (err == EM_STORAGE_ERROR_OUT_OF_MEMORY)
362                         err = EMF_ERROR_OUT_OF_MEMORY; else if (err == EM_STORAGE_ERROR_DB_FAILURE)
363                         err = EMF_ERROR_DB_FAILURE; else
364                         err = EMF_ERROR_UNKNOWN;
365                 
366                 return err;
367         } else {
368                 curr_mailbox = em_core_malloc(sizeof(emf_mailbox_t));
369                 memset(curr_mailbox, 0x00, sizeof(emf_mailbox_t));
370
371                 curr_mailbox->account_id = local_mailbox->account_id;
372                 if(local_mailbox->mailbox_name)
373                         curr_mailbox->name = strdup(local_mailbox->mailbox_name);
374                 curr_mailbox->local = local_mailbox->local_yn;
375                 if(local_mailbox->alias)
376                         curr_mailbox->alias= strdup(local_mailbox->alias);
377                 curr_mailbox->synchronous = local_mailbox->sync_with_server_yn;
378                 curr_mailbox->mailbox_type = local_mailbox->mailbox_type;
379                 curr_mailbox->unread_count = local_mailbox->unread_count;
380                 curr_mailbox->total_mail_count_on_local= local_mailbox->total_mail_count_on_local;
381                 curr_mailbox->total_mail_count_on_server= local_mailbox->total_mail_count_on_server;
382                 curr_mailbox->has_archived_mails = local_mailbox->has_archived_mails;
383                 curr_mailbox->mail_slot_size = local_mailbox->mail_slot_size;
384         }
385
386         *pMailbox = curr_mailbox;
387
388         em_storage_free_mailbox(&local_mailbox, 1, &err);
389         EM_DEBUG_FUNC_END("err [%d]", err);
390         return err;
391 }
392
393
394 EXPORT_API int email_get_child_mailbox_list(int account_id, const char *parent_mailbox,  emf_mailbox_t** mailbox_list, int* count)
395 {
396         EM_DEBUG_FUNC_BEGIN("account_id[%d], parent_mailbox[%p], mailbox_list[%p], count[%p]", account_id, parent_mailbox, mailbox_list, count);
397         
398         int err = EMF_ERROR_NONE;
399         int counter = 0;
400         emf_mailbox_tbl_t* mailbox_tbl = NULL; 
401         int i =0;
402         
403         EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM);
404         EM_IF_NULL_RETURN_VALUE(mailbox_list, EMF_ERROR_INVALID_PARAM);
405         EM_IF_NULL_RETURN_VALUE(count, EMF_ERROR_INVALID_PARAM);
406                 
407         *mailbox_list = NULL;
408         *count = 0;
409         
410         if (!em_storage_get_child_mailbox_list(account_id,(char*)parent_mailbox, &counter, &mailbox_tbl, true, &err))   {
411                 EM_DEBUG_EXCEPTION("em_storage_get_child_mailbox_list failed[%d]", err);
412                 
413                 err = em_storage_get_emf_error_from_em_storage_error(err);
414                 goto FINISH_OFF;
415         } else
416                 err = EMF_ERROR_NONE;
417         
418         if (counter > 0)  {
419                 if (!(*mailbox_list = em_core_malloc(sizeof(emf_mailbox_t) * counter)))  {
420                         EM_DEBUG_EXCEPTION("malloc failed for mailbox_list");
421                         
422                         err= EMF_ERROR_OUT_OF_MEMORY;
423                         goto FINISH_OFF;
424                 }
425
426                 memset(*mailbox_list, 0x00, (sizeof(emf_mailbox_t) * counter));
427                 
428                 for (i = 0; i < counter; i++)  {
429                         (*mailbox_list)[i].mailbox_id = mailbox_tbl[i].mailbox_id;
430                         (*mailbox_list)[i].account_id = account_id;
431                         (*mailbox_list)[i].name = mailbox_tbl[i].mailbox_name; mailbox_tbl[i].mailbox_name = NULL;
432                         (*mailbox_list)[i].alias = mailbox_tbl[i].alias; mailbox_tbl[i].alias = NULL;
433                         (*mailbox_list)[i].local = mailbox_tbl[i].local_yn;
434                         (*mailbox_list)[i].mailbox_type = mailbox_tbl[i].mailbox_type;
435                         (*mailbox_list)[i].synchronous = mailbox_tbl[i].sync_with_server_yn;
436                         (*mailbox_list)[i].unread_count = mailbox_tbl[i].unread_count;
437                         (*mailbox_list)[i].total_mail_count_on_local = mailbox_tbl[i].total_mail_count_on_local;
438                         (*mailbox_list)[i].total_mail_count_on_server = mailbox_tbl[i].total_mail_count_on_server;
439                         (*mailbox_list)[i].has_archived_mails = mailbox_tbl[i].has_archived_mails;
440                         (*mailbox_list)[i].mail_slot_size = mailbox_tbl[i].mail_slot_size;
441                 }
442         } else
443                 *mailbox_list = NULL;
444         
445         *count = counter;
446
447 FINISH_OFF:
448         if (mailbox_tbl != NULL)
449                 em_storage_free_mailbox(&mailbox_tbl, counter, NULL);
450         EM_DEBUG_FUNC_END("err [%d]", err);
451         return err;
452 }
453
454 /* sowmya.kr, 05-Apr-2010, new MAPI*/
455
456 EXPORT_API int email_get_mailbox_by_mailbox_type(int account_id, emf_mailbox_type_e mailbox_type,  emf_mailbox_t** mailbox)
457 {
458         EM_DEBUG_FUNC_BEGIN();
459         
460         int err = EMF_ERROR_NONE;
461         emf_mailbox_t* curr_mailbox = NULL;
462         emf_mailbox_tbl_t* local_mailbox = NULL;
463
464         EM_IF_NULL_RETURN_VALUE(mailbox, EMF_ERROR_INVALID_PARAM);      
465         EM_IF_NULL_RETURN_VALUE(account_id, EMF_ERROR_INVALID_PARAM)    ;
466
467
468         if(mailbox_type < EMF_MAILBOX_TYPE_INBOX || mailbox_type > EMF_MAILBOX_TYPE_ALL_EMAILS)
469                 return EMF_ERROR_INVALID_PARAM;
470         if (!em_storage_get_mailbox_by_mailbox_type(account_id, mailbox_type, &local_mailbox, true, &err))  {
471                 EM_DEBUG_EXCEPTION("em_storage_get_mailbox_by_mailbox_type failed [%d]", err);
472                 err = em_storage_get_emf_error_from_em_storage_error(err);
473                 goto FINISH_OFF;
474         } else {
475                 err = EMF_ERROR_NONE;
476                 curr_mailbox = em_core_malloc(sizeof(emf_mailbox_t));
477                 memset(curr_mailbox, 0x00, sizeof(emf_mailbox_t));
478
479                 curr_mailbox->account_id = local_mailbox->account_id;
480                 if(local_mailbox->mailbox_name)
481                         curr_mailbox->name = strdup(local_mailbox->mailbox_name);
482                 curr_mailbox->local = local_mailbox->local_yn;
483                 if(local_mailbox->alias)
484                         curr_mailbox->alias= strdup(local_mailbox->alias);
485                 curr_mailbox->synchronous = 1;
486                 curr_mailbox->mailbox_type = local_mailbox->mailbox_type;
487                 curr_mailbox->unread_count = local_mailbox->unread_count;
488                 curr_mailbox->total_mail_count_on_local = local_mailbox->total_mail_count_on_local;
489                 curr_mailbox->total_mail_count_on_server = local_mailbox->total_mail_count_on_server;
490                 curr_mailbox->has_archived_mails = local_mailbox->has_archived_mails;
491                 curr_mailbox->mail_slot_size = local_mailbox->mail_slot_size;
492         }
493
494         *mailbox = curr_mailbox;        
495 FINISH_OFF:
496
497         if(local_mailbox)
498                 em_storage_free_mailbox(&local_mailbox, 1, NULL);
499         EM_DEBUG_FUNC_END("err [%d]", err);
500         return err;
501 }
502
503 EXPORT_API int email_set_mail_slot_size(int account_id, char* mailbox_name, int new_slot_size/*, unsigned* handle*/)
504 {
505         EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], new_slot_size[%d]", account_id, mailbox_name, new_slot_size);
506
507         int err = EMF_ERROR_NONE, *handle = NULL;
508
509         if(new_slot_size < 0) {
510                 EM_DEBUG_EXCEPTION("new_slot_size should be greater than 0 or should be equal to 0");
511                 return EMF_ERROR_INVALID_PARAM;
512         }
513         
514         HIPC_API hAPI = ipcEmailAPI_Create(_EMAIL_API_SET_MAIL_SLOT_SIZE);      
515
516         EM_IF_NULL_RETURN_VALUE(hAPI, EMF_ERROR_NULL_VALUE);
517
518         if (hAPI) {
519                 if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &account_id, sizeof(int)))
520                         EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter for account_id failed");
521         
522                 if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, &new_slot_size, sizeof(int)))
523                         EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter for new_slot_size failed");
524                 
525                 if(mailbox_name) {
526                         if(!ipcEmailAPI_AddParameter(hAPI, ePARAMETER_IN, mailbox_name, strlen(mailbox_name) ))
527                                 EM_DEBUG_EXCEPTION(" ipcEmailAPI_AddParameter for mailbox_name failed");
528                 }
529                 
530                 if(!ipcEmailProxy_ExecuteAPI(hAPI)) {
531                         EM_DEBUG_EXCEPTION("ipcEmailProxy_ExecuteAPI failed");
532                         EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMF_ERROR_IPC_SOCKET_FAILURE);
533                 } else {
534                         err = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 0);
535                         EM_DEBUG_LOG("email_set_mail_slot_size error VALUE [%d]", err);
536                         if(handle) {
537                                 *handle = *(int*)ipcEmailAPI_GetParameter(hAPI, ePARAMETER_OUT, 1);
538                                 EM_DEBUG_LOG("email_set_mail_slot_size handle VALUE [%d]", handle);
539                         }
540                         ipcEmailAPI_Destroy(hAPI);
541                         hAPI = NULL;
542                 }
543         }
544         EM_DEBUG_FUNC_END("err [%d]", err);
545         return err;
546 }