Rollback the merged code
[platform/core/messaging/email-service.git] / email-core / email-core-imap-mailbox.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 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  * File :  email-core-imap_folder.c
26  * Desc :  Mail IMAP mailbox
27  *
28  * Auth : 
29  *
30  * History : 
31  *    2006.08.01  :  created
32  *****************************************************************************/
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <vconf.h>
37 #include "email-core-global.h"
38 #include "email-core-utils.h"
39 #include "email-storage.h"
40 #include "email-utilities.h"
41 #include "email-network.h"
42 #include "email-core-event.h"
43 #include "email-core-mailbox.h"
44 #include "email-core-imap-mailbox.h"
45 #include "email-core-mailbox-sync.h"
46 #include "email-core-account.h" 
47 #include "email-core-signal.h"
48
49 #include "lnx_inc.h"
50 #include "c-client.h"
51
52 #include "email-debug-log.h"
53
54 INTERNAL_FUNC int emcore_get_default_mail_slot_count(int input_account_id, int *output_count)
55 {       
56         EM_DEBUG_FUNC_BEGIN("input_account_id [%d] output_count[%p]", input_account_id, output_count);
57
58         int err = EMAIL_ERROR_NONE;
59         int default_mail_slot_count = 25;
60         email_account_t *account_ref = NULL;
61
62         if (output_count == NULL) {
63                 err = EMAIL_ERROR_INVALID_PARAM;
64                 goto FINISH_OFF;
65         }
66
67         account_ref = emcore_get_account_reference(input_account_id);
68         if (account_ref)
69                 default_mail_slot_count = account_ref->default_mail_slot_size;
70
71 FINISH_OFF: 
72
73         if (account_ref) {
74                 emcore_free_account(account_ref);
75                 EM_SAFE_FREE(account_ref);
76         }
77         
78         if (output_count)
79                 *output_count = default_mail_slot_count;
80
81         EM_DEBUG_FUNC_END("err[%d]", err);
82         return err;
83 }
84
85
86 INTERNAL_FUNC int emcore_remove_overflowed_mails(emstorage_mailbox_tbl_t *intput_mailbox_tbl, int *err_code)
87 {
88         EM_DEBUG_FUNC_BEGIN("intput_mailbox_tbl[%p], err_code[%p]", intput_mailbox_tbl, err_code);
89
90         int ret = false; 
91         int *mail_id_list = NULL, mail_id_list_count = 0;
92         int err = EMAIL_ERROR_NONE;
93         email_account_t *account_ref = NULL;
94         
95         if (!intput_mailbox_tbl || intput_mailbox_tbl->account_id < 1) {
96                 if (intput_mailbox_tbl)
97                 EM_DEBUG_EXCEPTION("Invalid Parameter. intput_mailbox_tbl->account_id [%d]", intput_mailbox_tbl->account_id);
98                 err = EMAIL_ERROR_INVALID_PARAM;
99                 goto FINISH_OFF;
100         }
101
102         account_ref = emcore_get_account_reference(intput_mailbox_tbl->account_id);
103         if (account_ref) {
104                 if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
105                         EM_DEBUG_LOG("ActiveSync Account didn't support mail slot");
106                         err = EMAIL_ERROR_NOT_SUPPORTED;
107                         goto FINISH_OFF;
108                 }
109         }
110         
111         if (!emstorage_get_overflowed_mail_id_list(intput_mailbox_tbl->account_id, intput_mailbox_tbl->mailbox_id, intput_mailbox_tbl->mail_slot_size, &mail_id_list, &mail_id_list_count, true, &err)) {
112                 if (err == EMAIL_ERROR_MAIL_NOT_FOUND) {
113                         EM_DEBUG_LOG_SEC("There are enough slot in intput_mailbox_tbl [%s]", intput_mailbox_tbl->mailbox_name);
114                         err = EMAIL_ERROR_NONE;
115                         ret = true;
116                 }
117                 else
118                         EM_DEBUG_EXCEPTION("emstorage_get_overflowed_mail_id_list failed [%d]", err);
119                 goto FINISH_OFF;
120         }
121
122         if (mail_id_list) {
123                 if (!emcore_delete_mail(intput_mailbox_tbl->account_id, mail_id_list, mail_id_list_count, EMAIL_DELETE_LOCALLY, EMAIL_DELETED_BY_OVERFLOW, false, &err)) {
124                         EM_DEBUG_EXCEPTION("emcore_delete_mail failed [%d]", err);
125                         goto FINISH_OFF;
126                 }
127         }
128         
129         ret = true;
130 FINISH_OFF: 
131         EM_SAFE_FREE(mail_id_list);
132
133         if (account_ref) {
134                 emcore_free_account(account_ref);
135                 EM_SAFE_FREE(account_ref);
136         }
137
138         if (err_code)
139                 *err_code = err;
140
141         EM_DEBUG_FUNC_END("ret [%d]", ret);
142         return ret;
143 }
144
145
146 INTERNAL_FUNC int emcore_set_mail_slot_size(int account_id, int mailbox_id, int new_slot_size, int *err_code)
147 {
148         EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id[%d], err_code[%p]", account_id, mailbox_id, err_code);
149
150         int ret = false, err = EMAIL_ERROR_NONE; 
151         int i = 0;
152         int account_count = 100;
153         int mailbox_count = 0;
154         email_account_t *account_ref = NULL;
155         emstorage_account_tbl_t *account_tbl_list = NULL;
156         emstorage_mailbox_tbl_t *mailbox_tbl_list = NULL;
157
158         if (account_id > ALL_ACCOUNT) {
159                 account_ref = emcore_get_account_reference(account_id);
160                 if (account_ref && account_ref->incoming_server_type == EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
161                         EM_DEBUG_LOG("ActiveSync account didn't support mail slot");
162                         ret = true;
163                         goto FINISH_OFF;
164                 }
165                 else if (!account_ref) {
166                         EM_DEBUG_EXCEPTION("emcore_get_account_reference failed");
167                         goto FINISH_OFF;
168                 }
169                 if (mailbox_id == 0) {
170                         if ( (err = emstorage_set_field_of_accounts_with_integer_value(account_id, "default_mail_slot_size", new_slot_size, true)) != EMAIL_ERROR_NONE) {
171                                 EM_DEBUG_EXCEPTION("emstorage_set_field_of_accounts_with_integer_value failed [%d]", err);
172                                 goto FINISH_OFF;
173                         }
174                 }
175         }
176         else {
177                 if (mailbox_id == 0) {
178                         if ( !emstorage_get_account_list(&account_count, &account_tbl_list, false, false, &err)) {
179                                 EM_DEBUG_EXCEPTION("emstorage_get_account_list failed [%d]", err);
180                                 goto FINISH_OFF;
181                         }
182                         for ( i = 0; i < account_count; i++) {
183                                 if ( (err = emstorage_set_field_of_accounts_with_integer_value(account_tbl_list[i].account_id, "default_mail_slot_size", new_slot_size, true)) != EMAIL_ERROR_NONE) {
184                                         EM_DEBUG_EXCEPTION("emstorage_set_field_of_accounts_with_integer_value failed [%d]", err);
185                                         goto FINISH_OFF;
186                                 }
187                         }
188                 }
189         }
190
191
192         if (!emstorage_set_mail_slot_size(account_id, mailbox_id, new_slot_size, true, &err)) {
193                 EM_DEBUG_EXCEPTION("emstorage_set_mail_slot_size failed [%d]", err);
194                 goto FINISH_OFF;
195         }
196
197         if (mailbox_id) {
198                 mailbox_count = 1;
199                 if (new_slot_size > 0) {
200                         mailbox_tbl_list = em_malloc(sizeof(emstorage_mailbox_tbl_t) * mailbox_count);
201                         if(!mailbox_tbl_list) {
202                                 EM_DEBUG_EXCEPTION("em_malloc failed");
203                                 goto FINISH_OFF;
204                         }
205                         mailbox_tbl_list->account_id = account_id;
206                         mailbox_tbl_list->mailbox_id = mailbox_id;
207                         mailbox_tbl_list->mail_slot_size = new_slot_size;     
208                 }
209                 else   {        /*  read information from DB */
210                         if ((err = emstorage_get_mailbox_by_id(mailbox_id, &mailbox_tbl_list)) != EMAIL_ERROR_NONE) {
211                                 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed [%d]", err);
212                                 goto FINISH_OFF;
213                         }
214                         
215                 }
216         }
217         else {
218                 if (!emstorage_get_mailbox_list(account_id, EMAIL_MAILBOX_ALL, EMAIL_MAILBOX_SORT_BY_NAME_ASC, &mailbox_count, &mailbox_tbl_list, true, &err)) {
219                         EM_DEBUG_EXCEPTION("emstorage_get_mailbox failed [%d]", err);
220                         goto FINISH_OFF;
221                 }
222         }
223
224         for (i = 0; i < mailbox_count; i++) {
225                 if (!emcore_remove_overflowed_mails(mailbox_tbl_list + i, &err)) {
226                         if (err == EMAIL_ERROR_MAIL_NOT_FOUND || err == EMAIL_ERROR_NOT_SUPPORTED)
227                                 err = EMAIL_ERROR_NONE;
228                         else
229                                 EM_DEBUG_EXCEPTION("emcore_remove_overflowed_mails failed [%d]", err);
230                 }
231         }
232
233         ret = true;
234         
235 FINISH_OFF: 
236
237         if (account_ref) {
238                 emcore_free_account(account_ref);
239                 EM_SAFE_FREE(account_ref);
240         }
241
242         if (account_tbl_list)
243                 emstorage_free_account(&account_tbl_list, account_count, NULL);
244
245         if (mailbox_tbl_list)
246                 emstorage_free_mailbox(&mailbox_tbl_list, mailbox_count, NULL);
247
248
249         if (err_code)
250                 *err_code = err;
251         return ret;
252 }
253
254 static int emcore_get_mailbox_connection_path(int account_id, char *mailbox_name, char **path, int *err_code)
255 {
256         EM_DEBUG_FUNC_BEGIN_SEC("account_id [%d], mailbox_name[%s], err_code[%p]", account_id, mailbox_name, err_code);
257         email_account_t *ref_account = NULL;
258         size_t path_len = 0;
259         int ret = false;
260         int err = EMAIL_ERROR_NONE;
261
262         ref_account = emcore_get_account_reference(account_id);
263         if (!ref_account)        {
264                 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed");
265                 goto FINISH_OFF;
266         }
267
268         path_len = EM_SAFE_STRLEN(ref_account->incoming_server_address) +
269                         (mailbox_name ? EM_SAFE_STRLEN(mailbox_name) : 0) + 50;
270
271         *path = em_malloc(path_len);/* EM_SAFE_STRLEN(ref_account->incoming_server_address) + */
272                                                                 /* (mailbox_name ? EM_SAFE_STRLEN(mailbox_name) : 0) + 20); */
273         if (!*path) {
274                 EM_DEBUG_EXCEPTION("em_malloc failed");
275                 err = EMAIL_ERROR_OUT_OF_MEMORY;
276                 goto FINISH_OFF;
277         }
278
279         memset(*path, 0x00, path_len);
280
281         /* 1. server address / server type */
282         if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) {
283                 SNPRINTF(*path + 1, path_len-1, "%s:%d/pop", ref_account->incoming_server_address, ref_account->incoming_server_port_number);
284         } else {
285                 SNPRINTF(*path + 1, path_len-1, "%s:%d/imap", ref_account->incoming_server_address, ref_account->incoming_server_port_number);
286         }
287
288         /* 2. set tls option if security connection */
289         /*if (ref_account->incoming_server_secure_connection) strncat(*path + 1, "/tls", path_len-(EM_SAFE_STRLEN(*path)-1));*/
290         if (ref_account->incoming_server_secure_connection & 0x01) {
291                 strncat(*path + 1, "/ssl", path_len-(EM_SAFE_STRLEN(*path)-1));
292         }
293         if (ref_account->incoming_server_secure_connection & 0x02)
294                 strncat(*path + 1, "/tls/force_tls_v1_0", path_len-(EM_SAFE_STRLEN(*path)-1));
295         else
296                 strncat(*path + 1, "/notls", path_len-(EM_SAFE_STRLEN(*path)-1));
297
298         /*  3. re-format mailbox name (ex:"{mai.test.com:143/imap} or {mai.test.com:143/imap/tls}"} */
299         strncat(*path + 1, "}", path_len-EM_SAFE_STRLEN(*path)-1);
300         **path = '{';
301
302         if (mailbox_name) strncat(*path, mailbox_name, path_len-EM_SAFE_STRLEN(*path)-1);
303
304         ret = true;
305
306 FINISH_OFF:
307
308         if (ref_account) {
309                 emcore_free_account(ref_account);
310                 EM_SAFE_FREE(ref_account);
311         }
312
313         if (!ret)
314                 return 0;
315
316         return 1;
317 }
318
319 static void emcore_find_mailbox_diff_between_local_and_remote (email_internal_mailbox_t *remote_box_list, 
320                                                 int remote_box_count, emstorage_mailbox_tbl_t *local_box_list, int local_box_count, 
321                                                 GList** remote_box_only, GList** local_box_only)
322 {
323         if ( !remote_box_only || !local_box_only ) {
324                 return ;
325         }
326         int i = 0;
327         GList *remote_head = NULL;
328         GList *local_head  = NULL;
329         GList *remote_p    = NULL;
330         GList *local_p     = NULL;
331
332         EM_DEBUG_LOG ("remote_box_count[%d] local_box_count[%d]", remote_box_count, local_box_count);
333
334         if (local_box_count == 0) {
335                 for (i=0 ; i<remote_box_count ; i++) {
336                         *remote_box_only = g_list_prepend (*remote_box_only, remote_box_list+i);
337                         *local_box_only = NULL;
338                 }
339                 return;
340         }
341
342         for (i=0; i<remote_box_count; i++)
343                 remote_head = g_list_prepend (remote_head, remote_box_list+i);
344
345         for (i=0; i<local_box_count; i++)
346                 local_head = g_list_prepend (local_head, local_box_list+i);
347
348         int matched = false;
349         for (remote_p = remote_head; remote_p ; remote_p = g_list_next (remote_p)) {
350                 matched = false ; /* initialized not matched for each iteration */
351                 email_internal_mailbox_t *remote_box = (email_internal_mailbox_t *) g_list_nth_data (remote_p, 0);
352                 EM_DEBUG_LOG_DEV ("remote [%s]",  remote_box->mailbox_name );
353                 /* find matching mailbox in local box */
354                 for (local_p = local_head; local_p ; local_p = g_list_next(local_p)) {
355                         emstorage_mailbox_tbl_t *local_box = (emstorage_mailbox_tbl_t *) g_list_nth_data (local_p, 0);
356                         /* if match found */
357                         EM_DEBUG_LOG_DEV ("vs local [%s]", local_box->mailbox_name);
358                         if (!EM_SAFE_STRCMP (remote_box->mailbox_name, local_box->mailbox_name)) {
359                                 /* It is unnecessary to compare the matched box in the next iteration, so remove it from local_box*/
360                                 local_head = g_list_delete_link (local_head, local_p);                          
361                                 matched = true;
362                                 break;
363                         }
364                 }
365                 /* if matching not found, add it to remote box */
366                 if (matched == false) {
367                         EM_DEBUG_LOG ("New box: name[%s] alias[%s]", remote_box->mailbox_name, remote_box->alias);
368                         *remote_box_only = g_list_prepend (*remote_box_only, remote_box);
369                 }
370         }
371
372         /* local_head contains unmatched local box */
373         *local_box_only = local_head;
374 }
375
376 INTERNAL_FUNC int emcore_sync_mailbox_list(int account_id, char *mailbox_name, int handle, int *err_code)
377 {
378         EM_DEBUG_FUNC_BEGIN("account_id[%d], mailbox_name[%p], handle[%d], err_code[%p]", account_id, mailbox_name, handle, err_code);
379         
380         int ret = false;
381         int err = EMAIL_ERROR_NONE;
382         int status = EMAIL_DOWNLOAD_FAIL;
383         MAILSTREAM *stream = NULL;
384         email_internal_mailbox_t *mailbox_list = NULL;   /* mailbox list from imap server */
385         /* mailbox list from DB */
386         emstorage_mailbox_tbl_t *local_mailbox_list = NULL;
387         int local_mailbox_count = 0;
388         GList *remote_box_only = NULL;
389         GList *local_box_only  = NULL;
390         email_account_t *ref_account = NULL;
391         void *tmp_stream = NULL;
392         char *mbox_path = NULL;
393         char *mailbox_name_for_mailbox_type = NULL;
394         int   i = 0, count = 0, counter = 0, mailbox_type_list[EMAIL_MAILBOX_TYPE_ALL_EMAILS + 1] = {-1, -1, -1, -1, -1, -1, -1, -1};
395         
396         if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_START, account_id, 0, handle, 0))
397                 EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SYNC_IMAP_MAILBOX_LIST_START] Failed >>>> ");
398
399         if (!emcore_check_thread_status())  {
400                 err = EMAIL_ERROR_CANCELLED;
401                 goto FINISH_OFF;
402         }
403         if (!emnetwork_check_network_status(&err)) {
404                 EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err);
405                 goto FINISH_OFF;
406         }
407         
408         ref_account = emcore_get_account_reference(account_id);
409         if (!ref_account)  {
410                 EM_DEBUG_EXCEPTION("emcore_get_account_reference failed - %d", account_id);
411                 err = EMAIL_ERROR_INVALID_ACCOUNT;
412                 goto FINISH_OFF;
413         }
414         
415         /* if not imap4 mail, return */
416         if ( ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
417                 EM_DEBUG_EXCEPTION("unsupported account...");
418                 err = EMAIL_ERROR_INVALID_ACCOUNT;
419                 goto FINISH_OFF;
420         }
421         
422         /*  get mail server path */
423         /*  mbox_path is not used. the below func might be unnecessary */
424         if (!emcore_get_mailbox_connection_path(account_id, NULL, &mbox_path, &err) || !mbox_path)  {
425                 EM_DEBUG_EXCEPTION("emcore_get_mailbox_connection_path - %d", err);
426                 goto FINISH_OFF;
427         }
428         
429         
430         if (!emcore_check_thread_status())  {
431                 err = EMAIL_ERROR_CANCELLED;
432                 goto FINISH_OFF;
433         }
434
435         stream = NULL;
436         if (!emcore_connect_to_remote_mailbox(account_id, 0, (void **)&tmp_stream, &err) || !tmp_stream)  {
437                 EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err);
438                 
439                 if (err == EMAIL_ERROR_CONNECTION_BROKEN)
440                         err = EMAIL_ERROR_CANCELLED;
441                 else
442                         err = EMAIL_ERROR_CONNECTION_FAILURE;
443                 
444                 status = EMAIL_DOWNLOAD_CONNECTION_FAIL;
445                 goto FINISH_OFF;
446         }
447         
448         EM_SAFE_FREE(mbox_path);
449         
450         stream = (MAILSTREAM *)tmp_stream;
451         
452         if (!emcore_check_thread_status())  {
453                 err = EMAIL_ERROR_CANCELLED;
454                 goto FINISH_OFF;
455         }
456         
457         /*  download mailbox list */
458         if (!emcore_download_mailbox_list(stream, mailbox_name, &mailbox_list, &count, &err))  {
459                 EM_DEBUG_EXCEPTION("emcore_download_mailbox_list failed [%d]", err);
460                 goto FINISH_OFF;
461         }
462
463         /* get all mailboxes which is previously synced */
464         if (!emstorage_get_mailbox_list (account_id, EMAIL_MAILBOX_FROM_SERVER, EMAIL_MAILBOX_SORT_BY_NAME_ASC,\
465                                                          &local_mailbox_count, &local_mailbox_list, 1, &err)) {
466                 if (err != EMAIL_ERROR_MAILBOX_NOT_FOUND) {
467                         EM_DEBUG_EXCEPTION("emstorage_get_mailbox_list error [%d]", err);
468                 }
469                 else
470                         EM_DEBUG_LOG ("mailbox not found");
471         }
472
473         if (!emcore_check_thread_status())  {
474                 err = EMAIL_ERROR_CANCELLED;
475                 goto FINISH_OFF;
476         }
477         
478         emcore_find_mailbox_diff_between_local_and_remote (mailbox_list, count, local_mailbox_list, local_mailbox_count,
479                                                                                         &remote_box_only, &local_box_only);
480
481         /* for remote_box_only, add new mailbox to DB */
482         GList *p = remote_box_only;
483         for (; p; p = g_list_next (p)) {
484                 email_internal_mailbox_t *new_mailbox = (email_internal_mailbox_t *) g_list_nth_data (p, 0);
485
486                 if (!emcore_check_thread_status())  {
487                         EM_DEBUG_LOG("emcore_check_thread_status - cancelled");
488                         err = EMAIL_ERROR_CANCELLED;
489                         goto FINISH_OFF;
490                 }
491
492                 if (!new_mailbox->mailbox_name) {
493                         continue;
494                 }
495
496                 /* EM_DEBUG_LOG_SEC ("mailbox name [%s]", new_mailbox->mailbox_name); */
497                 new_mailbox->mail_slot_size = ref_account->default_mail_slot_size;
498
499                 if (new_mailbox->mailbox_type == EMAIL_MAILBOX_TYPE_NONE)
500                         emcore_bind_mailbox_type (new_mailbox);
501
502                 if (new_mailbox->mailbox_type <= EMAIL_MAILBOX_TYPE_ALL_EMAILS) {       /* if result mailbox type is duplicated,  */
503                         if (mailbox_type_list[new_mailbox->mailbox_type] != -1) {
504                                 EM_DEBUG_LOG_SEC ("Mailbox type [%d] of [%s] is duplicated", new_mailbox->mailbox_type, new_mailbox->mailbox_name);
505                                 new_mailbox->mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED; /* ignore latest one  */
506                         }
507                         else
508                                 mailbox_type_list[new_mailbox->mailbox_type] = 1;
509                 }
510
511                 /* make box variable to be added in DB */
512                 emstorage_mailbox_tbl_t mailbox_tbl = {0};
513                 mailbox_tbl.mailbox_id     = new_mailbox->mailbox_id;
514                 mailbox_tbl.account_id     = new_mailbox->account_id;
515                 mailbox_tbl.local_yn       = 0;
516                 mailbox_tbl.deleted_flag   = 0;
517                 mailbox_tbl.mailbox_type   = new_mailbox->mailbox_type;
518                 mailbox_tbl.mailbox_name   = new_mailbox->mailbox_name;
519                 mailbox_tbl.mail_slot_size = new_mailbox->mail_slot_size;
520                 mailbox_tbl.no_select      = new_mailbox->no_select;
521
522                 /* Get the Alias Name after Parsing the Full mailbox Path */
523                 if (new_mailbox->alias == NULL)
524                         new_mailbox->alias = emcore_get_alias_of_mailbox ((const char *)new_mailbox->mailbox_name);
525
526                 if (new_mailbox->alias) {
527                         mailbox_tbl.alias = new_mailbox->alias;
528                         mailbox_tbl.modifiable_yn = 1; 
529                         mailbox_tbl.total_mail_count_on_server = 0;
530                                 
531                         if (!emstorage_add_mailbox (&mailbox_tbl, true, &err)) {
532                                 EM_DEBUG_EXCEPTION ("emstorage_add_mailbox error [%d]", err);
533                                 goto FINISH_OFF;
534                         }
535                         EM_DEBUG_LOG_SEC ("MAILBOX ADDED: mailbox_name [%s] alias [%s] mailbox_type [%d]", new_mailbox->mailbox_name,\
536                                                                 new_mailbox->alias, mailbox_tbl.mailbox_type);
537                 }
538         }
539
540         /* delete all local boxes and mails */
541         p = local_box_only;
542         for (; p; p = g_list_next (p)) {
543                 emstorage_mailbox_tbl_t *del_box = (emstorage_mailbox_tbl_t *) g_list_nth_data (p, 0);
544                 if (!emstorage_delete_mail_by_mailbox (del_box->account_id, del_box->mailbox_id, 1, &err)) {
545                         EM_DEBUG_EXCEPTION ("emstorage_delete_mail_by_mailbox error [%d] account_id [%d] mailbox_name [%s]",\
546                                                         err, del_box->account_id, del_box->mailbox_name);
547                 }
548                 if (!emstorage_delete_mailbox (del_box->account_id, EMAIL_MAILBOX_FROM_SERVER, del_box->mailbox_id, 1, &err)) {
549                         EM_DEBUG_EXCEPTION ("emstorage_delete_mail_by_mailbox error [%d] account_id [%d] mailbox_name [%s]",\
550                                                         err, del_box->account_id, del_box->mailbox_name);
551                 }
552                 EM_DEBUG_LOG_SEC ("MAILBOX REMOVED: mailbox_name[%s] mailbox_id[%d]", del_box->mailbox_name, del_box->mailbox_id);
553         }
554
555         for (counter = EMAIL_MAILBOX_TYPE_INBOX; counter <= EMAIL_MAILBOX_TYPE_OUTBOX; counter++) {
556                 if (mailbox_type_list[counter] == -1) {
557                         int err2 = EMAIL_ERROR_NONE;
558                         emstorage_mailbox_tbl_t mailbox_tbl;
559                         emstorage_mailbox_tbl_t *result_mailbox_tbl = NULL;
560
561                         if(emstorage_get_mailbox_by_mailbox_type(account_id, counter, &result_mailbox_tbl, true, &err2)) {
562                                 if(result_mailbox_tbl) {
563                                         emstorage_free_mailbox(&result_mailbox_tbl, 1, NULL);
564                                         continue;
565                                 }
566                         }
567
568                         memset(&mailbox_tbl, 0x00, sizeof(mailbox_tbl));
569
570                         mailbox_tbl.account_id = account_id;
571                         mailbox_tbl.mailbox_id = 0;
572                         mailbox_tbl.local_yn = 1;
573                         mailbox_tbl.mailbox_type = counter;
574                         mailbox_tbl.deleted_flag =  0;
575                         mailbox_tbl.modifiable_yn = 1;
576                         mailbox_tbl.total_mail_count_on_server = 0;
577                         mailbox_tbl.mail_slot_size = ref_account->default_mail_slot_size;
578
579                         switch (counter) {
580                                 case EMAIL_MAILBOX_TYPE_SENTBOX:
581                                         mailbox_tbl.mailbox_name = EMAIL_SENTBOX_NAME;
582                                         mailbox_tbl.alias = EMAIL_SENTBOX_DISPLAY_NAME;
583                                         break;
584
585                                 case EMAIL_MAILBOX_TYPE_TRASH:
586                                         mailbox_tbl.mailbox_name = EMAIL_TRASH_NAME;
587                                         mailbox_tbl.alias = EMAIL_TRASH_DISPLAY_NAME;
588                                         break;
589
590                                 case EMAIL_MAILBOX_TYPE_DRAFT:
591                                         mailbox_tbl.mailbox_name = EMAIL_DRAFTBOX_NAME;
592                                         mailbox_tbl.alias = EMAIL_DRAFTBOX_DISPLAY_NAME;
593                                         break;
594
595                                 case EMAIL_MAILBOX_TYPE_SPAMBOX:
596                                         mailbox_tbl.mailbox_name = EMAIL_SPAMBOX_NAME;
597                                         mailbox_tbl.alias = EMAIL_SPAMBOX_DISPLAY_NAME;
598                                         break;
599
600                                 case EMAIL_MAILBOX_TYPE_OUTBOX:
601                                         mailbox_tbl.mailbox_name = EMAIL_OUTBOX_NAME;
602                                         mailbox_tbl.alias = EMAIL_OUTBOX_DISPLAY_NAME;
603                                         break;
604
605                                 default:
606                                         mailbox_tbl.mailbox_name = EMAIL_INBOX_NAME;
607                                         mailbox_tbl.alias = EMAIL_INBOX_DISPLAY_NAME;
608                                         break;
609                         }
610
611                         if (!emstorage_add_mailbox(&mailbox_tbl, true, &err)) {
612                                 EM_DEBUG_EXCEPTION("emstorage_add_mailbox failed - %d", err);
613                                 goto FINISH_OFF;
614                         }
615                 }
616                 EM_SAFE_FREE(mailbox_name_for_mailbox_type);
617         }
618         if (!emstorage_set_all_mailbox_modifiable_yn(account_id, 0, true, &err)) {
619                 EM_DEBUG_EXCEPTION(" >>>> emstorage_set_all_mailbox_modifiable_yn Failed [ %d ]", err);
620                 goto FINISH_OFF;
621         }
622         
623         if (!emcore_check_thread_status())  {
624                 err = EMAIL_ERROR_CANCELLED;
625                 goto FINISH_OFF;
626         }
627         
628         for (i = 0; i < count; i++)
629                 mailbox_list[i].account_id = account_id;
630         
631         
632         ret = true;
633         
634 FINISH_OFF: 
635
636         if (err == EMAIL_ERROR_NONE) {
637                 if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH, account_id, 0, handle, err))
638                         EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SYNC_IMAP_MAILBOX_LIST_FINISH] Failed >>>> ");
639         }
640         else {
641                 if (!emcore_notify_network_event(NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL, account_id, 0, handle, err))
642                         EM_DEBUG_EXCEPTION("emcore_notify_network_event [ NOTI_SYNC_IMAP_MAILBOX_LIST_FAIL] Failed >>>> ");
643         }
644         EM_SAFE_FREE(mailbox_name_for_mailbox_type);
645         EM_SAFE_FREE(mbox_path);
646
647         if (ref_account) {
648                 emcore_free_account(ref_account);
649                 EM_SAFE_FREE(ref_account);
650         }
651
652         if (stream) 
653                 stream = mail_close (stream);
654         
655         if (mailbox_list) 
656                 emcore_free_internal_mailbox (&mailbox_list, count, NULL);
657
658         if (local_mailbox_list) 
659                 emstorage_free_mailbox (&local_mailbox_list, local_mailbox_count, NULL);
660
661         if (local_box_only) 
662                 g_list_free (local_box_only);
663
664         if (remote_box_only)
665                 g_list_free (remote_box_only);
666
667         if (err_code != NULL)
668                 *err_code = err;
669         EM_DEBUG_FUNC_END("ret [%d]", ret);
670         return ret;
671 }
672
673 int emcore_download_mailbox_list(void *mail_stream, 
674                                                                                 char *mailbox_name,
675                                                                                 email_internal_mailbox_t **mailbox_list,
676                                                                                 int *count, 
677                                                                                 int *err_code)
678 {
679         EM_DEBUG_FUNC_BEGIN("mail_stream [%p], mailbox_name [%p], mailbox_list [%p], count [%p], err_code [%p]", mail_stream, mailbox_name, mailbox_list, count, err_code);
680
681         MAILSTREAM *stream = mail_stream;
682         email_callback_holder_t holder;
683         char *pattern = NULL;
684         char *reference = NULL;
685         int   err = EMAIL_ERROR_NONE;
686         int   ret = false;
687
688         if (!stream || !mailbox_list || !count) {
689                 err = EMAIL_ERROR_INVALID_PARAM;
690                 goto FINISH_OFF;
691         }
692         
693         memset(&holder, 0x00, sizeof(holder));
694
695     /*  reference (ex : "{mail.test.com}", "{mail.test.com}inbox") */
696         if (mailbox_name)  {
697                 char *s = NULL;
698                 reference = em_malloc(EM_SAFE_STRLEN(stream->original_mailbox) + strlen(mailbox_name) + 1); /*prevent 34352*/
699                 if (reference) {
700                         strncpy(reference, stream->original_mailbox, (size_t)EM_SAFE_STRLEN(stream->original_mailbox));
701                         if ((s = strchr(reference, '}')))
702                                 *(++s) = '\0';
703                         strcat(reference, mailbox_name);
704                 }
705         }
706         else
707                 reference = EM_SAFE_STRDUP(stream->original_mailbox);
708
709         pattern        = "*";
710         stream->sparep = &holder;
711
712         /*  imap command : tag LIST reference * */
713         /*  see callback function mm_list */
714         mail_list (stream, reference, pattern);
715
716         stream->sparep = NULL;
717
718         EM_SAFE_FREE(reference);
719
720         *count        = holder.num;
721         *mailbox_list = (email_internal_mailbox_t*) holder.data;
722
723         ret = true;
724
725 FINISH_OFF: 
726         if (err_code)
727                 *err_code = err;
728
729         return ret;
730 }
731
732 /* description
733  *    create a new imap mailbox
734  * arguments
735  *    new_mailbox  :  imap mailbox to be created
736  * return
737  *    succeed  :  1
738  *    fail  :  0
739  */
740 INTERNAL_FUNC int emcore_create_imap_mailbox(email_mailbox_t *mailbox, int *err_code)
741 {
742         MAILSTREAM *stream = NULL;
743         char *long_enc_path = NULL;
744         void *tmp_stream = NULL;
745         int ret = false;
746         int err = EMAIL_ERROR_NONE;
747
748         EM_DEBUG_FUNC_BEGIN();
749
750         if (!mailbox) {
751                 err = EMAIL_ERROR_INVALID_PARAM;
752                 goto FINISH_OFF;
753         }
754
755         /* connect mail server */
756         stream = NULL;
757         if (!emcore_connect_to_remote_mailbox(mailbox->account_id, 0, (void **)&tmp_stream, &err)) {
758                 EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
759                 goto FINISH_OFF;
760         }
761
762         stream = (MAILSTREAM *) tmp_stream;
763
764         /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
765         if (!emcore_get_long_encoded_path(mailbox->account_id, mailbox->mailbox_name, '/', &long_enc_path, &err)) {
766                 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed [%d]", err);
767                 goto FINISH_OFF;
768         }
769
770         /* create mailbox */
771         if (!mail_create(stream, long_enc_path)) {
772                 EM_DEBUG_EXCEPTION("mail_create failed");
773                 err = EMAIL_ERROR_IMAP4_CREATE_FAILURE;
774                 goto FINISH_OFF;
775         }
776
777         EM_SAFE_FREE(long_enc_path);
778
779         ret = true;
780
781 FINISH_OFF:
782         if (stream) {
783                 stream = mail_close (stream);
784         }
785
786         EM_SAFE_FREE(long_enc_path);
787
788         if (mailbox) {
789                 if (err == EMAIL_ERROR_NONE) {
790                         if (!emcore_notify_network_event (NOTI_ADD_MAILBOX_FINISH, mailbox->account_id, mailbox->mailbox_name, 0, 0))
791                                 EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_ADD_MAILBOX_FINISH] failed");
792                 }
793                 else if (!emcore_notify_network_event (NOTI_ADD_MAILBOX_FAIL, mailbox->account_id, mailbox->mailbox_name, 0, err))
794                         EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_ADD_MAILBOX_FAIL] failed");
795         }
796
797         if (err_code)
798                 *err_code = err;
799
800         return ret;
801 }
802
803
804 /* description
805  *    delete a imap mailbox
806  * arguments
807  *    input_mailbox_id  :  mailbox ID to be deleted
808  * return
809  *    succeed  :  1
810  *    fail  :  0
811  */
812 INTERNAL_FUNC int emcore_delete_imap_mailbox(int input_mailbox_id, int *err_code)
813 {
814         EM_DEBUG_FUNC_BEGIN();
815
816         MAILSTREAM *stream = NULL;
817         char *long_enc_path = NULL;
818         email_account_t *ref_account = NULL;
819         void *tmp_stream = NULL;
820         int ret = false;
821         int err = EMAIL_ERROR_NONE;
822         emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
823
824         if(!emcore_notify_network_event(NOTI_DELETE_MAILBOX_START, input_mailbox_id, 0, 0, 0))
825                 EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_DELETE_MAILBOX_START] failed");
826
827         if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
828                 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
829                 goto FINISH_OFF;
830         }
831
832         ref_account = emcore_get_account_reference(mailbox_tbl->account_id);
833
834         if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
835                 EM_DEBUG_EXCEPTION("Invalid account information");
836                 err = EMAIL_ERROR_INVALID_ACCOUNT;
837                 goto FINISH_OFF;
838         }
839
840         /* connect mail server */
841         if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&tmp_stream, &err)) {
842                 EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
843                 goto FINISH_OFF;
844         }
845
846         stream = (MAILSTREAM *)tmp_stream;
847
848         /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
849         if (!emcore_get_long_encoded_path(mailbox_tbl->account_id, mailbox_tbl->mailbox_name, '/', &long_enc_path, &err)) {
850                 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed [%d]", err);
851                 goto FINISH_OFF;
852         }
853
854         /* delete mailbox */
855         if (!mail_delete(stream, long_enc_path)) {
856                 EM_DEBUG_EXCEPTION("mail_delete failed");
857                 err = EMAIL_ERROR_IMAP4_DELETE_FAILURE;
858                 goto FINISH_OFF;
859         }
860
861         EM_SAFE_FREE(long_enc_path);
862
863         ret = true;
864
865 FINISH_OFF:
866         if (stream) {
867                 stream = mail_close (stream);
868         }
869
870         if (ref_account) {
871                 emcore_free_account(ref_account);
872                 EM_SAFE_FREE(ref_account);
873         }
874
875         EM_SAFE_FREE(long_enc_path);
876
877         if (mailbox_tbl)
878                 emstorage_free_mailbox(&mailbox_tbl, 1, NULL);
879
880         if (err == EMAIL_ERROR_NONE) {
881                 if(!emcore_notify_network_event(NOTI_DELETE_MAILBOX_FINISH, input_mailbox_id, 0, 0, 0))
882                         EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_ADD_MAILBOX_FINISH] failed");
883         }
884         else if (!emcore_notify_network_event(NOTI_DELETE_MAILBOX_FAIL, input_mailbox_id, 0, 0, err))
885                 EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_ADD_MAILBOX_FAIL] failed");
886
887         if (err_code)
888                 *err_code = err;
889
890         return ret;
891 }
892
893
894 INTERNAL_FUNC int emcore_rename_mailbox_on_imap_server(int input_account_id, int input_mailbox_id, char *input_old_mailbox_path, char *input_new_mailbox_path, int handle_to_be_published)
895 {
896         EM_DEBUG_FUNC_BEGIN("input_account_id [%d], input_mailbox_id [%d], input_old_mailbox_path [%p], input_new_mailbox_path [%p] handle_to_be_published[%d]", input_account_id, input_mailbox_id, input_old_mailbox_path, input_new_mailbox_path, handle_to_be_published);
897         MAILSTREAM *stream = NULL;
898         char *long_enc_path_old = NULL;
899         char *long_enc_path_new = NULL;
900         email_account_t *ref_account = NULL;
901         void *tmp_stream = NULL;
902         int err = EMAIL_ERROR_NONE;
903
904         if (!input_old_mailbox_path || !input_new_mailbox_path) {
905                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
906                 err = EMAIL_ERROR_INVALID_PARAM;
907                 goto FINISH_OFF;
908         }
909
910         ref_account = emcore_get_account_reference(input_account_id);
911
912         if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
913                 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_ACCOUNT");
914                 err = EMAIL_ERROR_INVALID_ACCOUNT;
915                 goto FINISH_OFF;
916         }
917
918         /* connect mail server */
919         stream = NULL;
920         if (!emcore_connect_to_remote_mailbox(input_account_id, 0, (void **)&tmp_stream, &err)) {
921                 EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed. [%d]", err);
922                 goto FINISH_OFF;
923         }
924
925         stream = (MAILSTREAM *)tmp_stream;
926
927         /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
928         if (!emcore_get_long_encoded_path(input_account_id, input_old_mailbox_path, '/', &long_enc_path_old, &err)) {
929                 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed. [%d]", err);
930                 goto FINISH_OFF;
931         }
932
933         /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
934         if (!emcore_get_long_encoded_path(input_account_id, input_new_mailbox_path, '/', &long_enc_path_new, &err)) {
935                 EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed. [%d]", err);
936                 goto FINISH_OFF;
937         }
938
939         /* rename mailbox */
940         if (!mail_rename(stream, long_enc_path_old, long_enc_path_new)) {
941                 err = EMAIL_ERROR_IMAP4_RENAME_FAILURE;
942                 goto FINISH_OFF;
943         }
944
945 FINISH_OFF:
946
947         if (err  == EMAIL_ERROR_NONE) {
948                 if(!emcore_notify_network_event(NOTI_RENAME_MAILBOX_FINISH, input_mailbox_id, input_new_mailbox_path, handle_to_be_published, 0))
949                         EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_RENAME_MAILBOX_FINISH] failed");
950         }
951         else {
952                 if (!emcore_notify_network_event(NOTI_RENAME_MAILBOX_FAIL, input_mailbox_id, input_new_mailbox_path, handle_to_be_published, 0))
953                         EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_RENAME_MAILBOX_FAIL] failed");
954         }
955         EM_SAFE_FREE(long_enc_path_old);
956         EM_SAFE_FREE(long_enc_path_new);
957
958         if (ref_account) {
959                 emcore_free_account(ref_account);
960                 EM_SAFE_FREE(ref_account);
961         }
962
963         if (stream) {
964                 stream = mail_close (stream);
965         }
966
967         EM_DEBUG_FUNC_END("err [%d]", err);
968         return err;
969 }
970
971
972 #ifdef __FEATURE_IMAP_QUOTA__
973
974 quota_t callback_for_get_quota_root(MAILSTREAM *stream, unsigned char *mailbox, STRINGLIST *quota_root_list)
975 {
976         EM_DEBUG_FUNC_BEGIN();
977         quota_t ret_quota;
978         EM_DEBUG_FUNC_END();
979         return ret_quota;
980 }
981
982 quota_t callback_for_get_quota(MAILSTREAM *stream, unsigned char *quota_root, QUOTALIST *quota_list)
983 {
984         EM_DEBUG_FUNC_BEGIN();
985         quota_t ret_quota;
986         EM_DEBUG_FUNC_END();
987         return ret_quota;
988 }
989
990
991 INTERNAL_FUNC int emcore_register_quota_callback()
992 {
993         EM_DEBUG_FUNC_BEGIN();
994         int err = EMAIL_ERROR_NONE;
995
996         mail_parameters(NULL, SET_QUOTAROOT, callback_for_get_quota_root); /* set callback function for handling quota root message */
997         mail_parameters(NULL, SET_QUOTA,     callback_for_get_quota);      /* set callback function for handling quota message */
998
999         EM_DEBUG_FUNC_END("err [%d]", err);
1000         return err;
1001 }
1002
1003 INTERNAL_FUNC int emcore_get_quota_root(int input_mailbox_id, email_quota_resource_t *output_list_of_resource_limits)
1004 {
1005         EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d], output_list_of_resource_limits[%p]", input_mailbox_id, output_list_of_resource_limits);
1006         int err = EMAIL_ERROR_NONE;
1007         MAILSTREAM *stream = NULL;
1008         email_account_t *ref_account = NULL;
1009         emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
1010
1011         if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
1012                 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
1013                 goto FINISH_OFF;
1014         }
1015
1016         ref_account = emcore_get_account_reference(mailbox_tbl->account_id);
1017
1018         if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
1019                 EM_DEBUG_EXCEPTION("Invalid account information");
1020                 err = EMAIL_ERROR_INVALID_ACCOUNT;
1021                 goto FINISH_OFF;
1022         }
1023
1024         /* connect mail server */
1025         if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&stream, &err)) {
1026                 EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
1027                 goto FINISH_OFF;
1028         }
1029
1030         imap_getquotaroot(stream, mailbox_tbl->mailbox_name);
1031
1032 FINISH_OFF:
1033
1034         EM_DEBUG_FUNC_END("err [%d]", err);
1035         return err;
1036 }
1037
1038 INTERNAL_FUNC int emcore_get_quota(int input_mailbox_id, char *input_quota_root, email_quota_resource_t *output_list_of_resource_limits)
1039 {
1040         EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_quota_root[%p] output_list_of_resource_limits[%p]", input_mailbox_id, input_quota_root, output_list_of_resource_limits);
1041         int err = EMAIL_ERROR_NONE;
1042         MAILSTREAM *stream = NULL;
1043         email_account_t *ref_account = NULL;
1044         emstorage_mailbox_tbl_t *mailbox_tbl = NULL;
1045
1046         if ((err = emstorage_get_mailbox_by_id(input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
1047                 EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
1048                 goto FINISH_OFF;
1049         }
1050
1051         ref_account = emcore_get_account_reference(mailbox_tbl->account_id);
1052
1053         if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
1054                 EM_DEBUG_EXCEPTION("Invalid account information");
1055                 err = EMAIL_ERROR_INVALID_ACCOUNT;
1056                 goto FINISH_OFF;
1057         }
1058
1059         /* connect mail server */
1060         if (!emcore_connect_to_remote_mailbox(mailbox_tbl->account_id, 0, (void **)&stream, &err)) {
1061                 EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
1062                 goto FINISH_OFF;
1063         }
1064
1065         imap_getquota(stream, input_quota_root);
1066
1067 FINISH_OFF:
1068         EM_DEBUG_FUNC_END("err [%d]", err);
1069         return err;
1070 }
1071
1072 INTERNAL_FUNC int emcore_set_quota(int input_mailbox_id, char *input_quota_root, email_quota_resource_t *input_list_of_resource_limits)
1073 {
1074         EM_DEBUG_FUNC_BEGIN("input_mailbox_id[%d] input_quota_root[%p] output_list_of_resource_limits[%p]", input_mailbox_id, input_quota_root, input_list_of_resource_limits);
1075         int err = EMAIL_ERROR_NONE;
1076         /* TODO : set quota using the function 'imap_setquota' */
1077
1078         EM_DEBUG_FUNC_END("err [%d]", err);
1079         return err;
1080 }
1081
1082 #endif /* __FEATURE_IMAP_QUOTA__ */