- }
-
- /* select the mailbox and get its UID */
- if (!imap_local || !imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) {
- EM_DEBUG_EXCEPTION("network error - failed to IDLE on Mailbox [%s]", mailbox->mailbox_name);
- /*
- err = EMAIL_ERROR_CONNECTION_BROKEN;
- if(imap_local)
- imap_local->netstream = NULL;
- mailbox->mail_stream = NULL;
- goto JOB_ERROR;
- */
- }
- else {
- EM_DEBUG_LOG("Get response for select call");
- while (imap_local->netstream) {
- p = net_getline(imap_local->netstream);
- EM_DEBUG_LOG("p =[%s]", p);
- if (!strncmp(p, "+", 1)) {
- ret = 1;
- break;
- }
- else if (!strncmp(p, "*", 1)) {
- EM_SAFE_FREE(p);
- continue;
- }
- else {
- ret = 0;
- break;
- }
- }
- EM_SAFE_FREE(p);
- EM_DEBUG_LINE;
- /* check if OK or BAD response comes. */
- /* if response is OK the try getting UID list. */
- if (!strncmp((char *)imap_local->reply.key, "OK", strlen("OK"))) {
- EM_DEBUG_LOG(">>>>>>>>>>Select success on %s mailbox", mailbox->mailbox_name);
- if (!imap4_mailbox_get_uids(stream, &uid_list, &err)) {
- EM_DEBUG_EXCEPTION("imap4_mailbox_get_uids failed - %d", err);
- EM_SAFE_FREE(uid_list);
- }
- else {
- if (!emstorage_get_downloaded_list(mailbox->account_id, 0, &downloaded_uids, &j, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_downloaded_list failed [%d]", err);
-
- downloaded_uids = NULL;
- }
- else /* Prevent Defect - 28497 */ {
- emcore_uid_list *uid_elem = uid_list;
- emcore_uid_list *next_uid_elem = NULL;
- if (uid_elem) {
- for (i = j; (i > 0 && !mailbox_renamed); i--) {
- if (uid_elem) {
- next_uid_elem = uid_elem->next;
- if (uid_elem->uid && downloaded_uids[i - 1].s_uid && !strcmp(uid_elem->uid, downloaded_uids[i - 1].s_uid)) {
- temp = i-1;
- mailbox_renamed = 1;
- break;
- }
- EM_SAFE_FREE(uid_elem->uid);
- uid_elem = next_uid_elem;
- }
- }
- }
- }
- }
- } /* mailbox selected */
- }
-
- if (mailbox_renamed) /* renamed mailbox */ {
- EM_DEBUG_LOG("downloaded_uids[temp].mailbox_name [%s]", downloaded_uids[temp].mailbox_name);
- /* Do a mailbox rename in the DB */
- if (!emstorage_modify_mailbox_of_mails(downloaded_uids[temp].mailbox_name, mailbox->mailbox_name, true, &err))
- EM_DEBUG_EXCEPTION(" emstorage_modify_mailbox_of_mails Failed [%d]", err);
-
- mailbox_renamed = 0;
-
- memset(&mailbox_tbl, 0, sizeof(emstorage_mailbox_tbl_t));
-
- mailbox_tbl.account_id = mailbox->account_id;
- mailbox_tbl.local_yn = 0;
- mailbox_tbl.mailbox_name = mailbox->mailbox_name;
- mailbox_tbl.mailbox_type = mailbox->mailbox_type;
-
- /* Get the Alias Name after parsing the Full mailbox Path */
- if(mailbox->alias == NULL)
- mailbox->alias = emcore_get_alias_of_mailbox((const char *)mailbox->mailbox_name);
-
- mailbox_tbl.alias = mailbox->alias;
- mailbox_tbl.deleted_flag = 1;
- mailbox_tbl.modifiable_yn = 1;
- mailbox_tbl.total_mail_count_on_server = 0;
-
- /* if non synchronous, delete imap mailbox from db */
- if (!emstorage_update_mailbox(mailbox->account_id, 0, downloaded_uids[temp].mailbox_id, &mailbox_tbl, true, &err)) {
- EM_DEBUG_EXCEPTION(" emstorage_update_mailbox Failed [ %d ] ", err);
- goto JOB_ERROR;
- }
-
- }
- else /* Its a Fresh Mailbox */ {
- memset(&mailbox_tbl, 0, sizeof(emstorage_mailbox_tbl_t));
-
- mailbox_tbl.mailbox_id = mailbox->mailbox_id;
- mailbox_tbl.account_id = mailbox->account_id;
- mailbox_tbl.local_yn = 0;
- mailbox_tbl.deleted_flag = 0;
- mailbox_tbl.mailbox_type = mailbox->mailbox_type;
- mailbox_tbl.mailbox_name = mailbox->mailbox_name;
- mailbox_tbl.mail_slot_size = mailbox->mail_slot_size;
- mailbox_tbl.no_select = mailbox->no_select;
-
- /* Get the Alias Name after Parsing the Full mailbox Path */
- if(mailbox->alias == NULL)
- mailbox->alias = emcore_get_alias_of_mailbox((const char *)mailbox->mailbox_name);
-
- if (mailbox->alias) {
- EM_DEBUG_LOG("mailbox->alias [%s] ", mailbox->alias);
-
- mailbox_tbl.alias = mailbox->alias;
- mailbox_tbl.modifiable_yn = 1;
- mailbox_tbl.total_mail_count_on_server = 0;
-
- EM_DEBUG_LOG("mailbox_tbl.mailbox_type - %d", mailbox_tbl.mailbox_type);
-
- if (!emstorage_add_mailbox(&mailbox_tbl, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_add_mailbox failed - %d", err);
- goto JOB_ERROR;
- }
- }
- }
- }
- }
+ if (!emcore_notify_network_event(NOTI_DELETE_MAILBOX_START, input_mailbox_id, 0, 0, 0))
+ EM_DEBUG_EXCEPTION("emcore_notify_network_event[NOTI_DELETE_MAILBOX_START] failed");
+
+ if ((err = emstorage_get_mailbox_by_id(multi_user_name, input_mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE || !mailbox_tbl) {
+ EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ ref_account = emcore_get_account_reference(multi_user_name, mailbox_tbl->account_id, false);
+ if (!ref_account || ref_account->incoming_server_type != EMAIL_SERVER_TYPE_IMAP4) {
+ EM_DEBUG_EXCEPTION("Invalid account information");
+ err = EMAIL_ERROR_INVALID_ACCOUNT;
+ goto FINISH_OFF;
+ }
+
+ /* connect mail server */
+ if (!emcore_connect_to_remote_mailbox(multi_user_name,
+ mailbox_tbl->account_id,
+ 0,
+ true,
+ (void **)&tmp_stream,
+ &err)) {
+ EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ stream = (MAILSTREAM *)tmp_stream;
+
+ /* encode mailbox name by UTF7, and rename to full path (ex : {mail.test.com}child_mailbox) */
+ if (!emcore_get_long_encoded_path(multi_user_name, mailbox_tbl->account_id, mailbox_tbl->mailbox_name, '/', &long_enc_path, &err)) {
+ EM_DEBUG_EXCEPTION("emcore_get_long_encoded_path failed [%d]", err);
+ goto FINISH_OFF;
+ }
+
+ /* delete mailbox */
+ if (!mail_delete(stream, long_enc_path)) {
+ EM_DEBUG_EXCEPTION("mail_delete failed");
+ err = EMAIL_ERROR_IMAP4_DELETE_FAILURE;
+ goto FINISH_OFF;