4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
32 #include "Emf_Mapi_Message.h"
33 #include "Emf_Mapi_Network.h"
34 #include "Emf_Mapi_Mailbox.h"
37 #include "emf-test-utility.h"
38 #include "emf-test-mailbox.h"
41 static gboolean testapp_test_add_mailbox()
44 int account_id,mailbox_type = 0;
50 memset(arg, 0x00, 500);
51 testapp_print("\n> Enter mailbox name: ");
53 mbox.name = strdup(arg);
55 memset(arg, 0x00, 500);
56 testapp_print("> Enter mailbox alias name: ");
58 mbox.alias = strdup(arg);
60 testapp_print("> Enter account id: ");
61 scanf("%d", &account_id);
62 mbox.account_id = account_id;
64 testapp_print("> Enter local_yn (1/0): ");
65 scanf("%d", &local_yn);
69 testapp_print("> Enter mailbox type: ");
70 scanf("%d", &mailbox_type);
71 mbox.mailbox_type= mailbox_type;
73 ret = email_add_mailbox(&mbox, local_yn?0:1, &handle);
76 testapp_print("\n email_add_mailbox failed");
79 testapp_print("\n email_add_mailbox succeed : handle[%d]\n", handle);
85 static gboolean testapp_test_delete_mailbox()
95 memset(arg, 0x00, 500);
96 testapp_print("\n> Enter mailbox name:");
98 mbox.name = strdup(arg);
100 testapp_print("> Enter account id: ");
101 scanf("%d", &account_id);
102 mbox.account_id = account_id;
104 testapp_print("> Enter local_yn (1/0): ");
105 scanf("%d", &local_yn);
107 ret = email_delete_mailbox(&mbox, local_yn?0:1, &handle);
110 testapp_print("\n email_delete_mailbox failed");
113 testapp_print("\n email_delete_mailbox succeed : handle[%d]\n", handle);
120 static gboolean testapp_test_update_mailbox()
122 testapp_print ("testapp_test_update_mailbox - support ONLY updating mailbox type\n");
123 emf_mailbox_t *old_mailbox_name = NULL;
124 emf_mailbox_t *new_mbox = NULL;
125 int account_id,mailbox_type = 0;
129 memset(arg, 0x00, 500);
131 testapp_print("> Enter account id: ");
132 scanf("%d", &account_id);
134 testapp_print("\n> Enter mailbox name: ");
137 testapp_print("> Enter mailbox type: ");
138 scanf("%d", &mailbox_type);
140 /* Get old mailbox information from db */
141 if ( (err = email_get_mailbox_by_name(account_id, arg, &old_mailbox_name)) < 0 ) {
142 testapp_print("\n email_get_mailbox_by_name failed[%d]\n", err);
145 testapp_print("\n email_get_mailbox_by_name succeed\n");
148 /* copy old maibox to new mailbox */
149 if ( (err = email_get_mailbox_by_name(account_id, arg, &new_mbox)) < 0 ) {
150 testapp_print("\n email_get_mailbox_by_name failed[%d]\n", err);
153 testapp_print("\n email_get_mailbox_by_name succeed\n");
156 /* set new value of new mailbox */
157 new_mbox->mailbox_type= mailbox_type;
159 if ( (err = email_update_mailbox(old_mailbox_name, new_mbox)) < 0) {
160 testapp_print("\n email_update_mailbox failed[%d]\n", err);
163 testapp_print("\n email_update_mailbox succeed\n");
166 email_free_mailbox(&old_mailbox_name, 1);
167 email_free_mailbox(&new_mbox, 1);
172 static gboolean testapp_test_get_imap_mailbox_list()
177 testapp_print("> Enter account id: ");
178 scanf("%d", &account_id);
180 if( email_get_imap_mailbox_list(account_id, "", &handle) < 0)
181 testapp_print("email_get_imap_mailbox_list failed");
187 static gboolean testapp_test_get_child_mailbox_list ()
192 int i = 0, err_code = EMF_ERROR_NONE;
193 emf_mailbox_t *mailbox_list=NULL;
194 char parent_mailbox[100], *parent_mailbox_pointer = NULL;
197 memset(parent_mailbox,0x00,sizeof(parent_mailbox));
199 testapp_print("\n > Enter account id: ");
200 scanf("%d", &account_id);
202 testapp_print("\n > Enter parent mailbox name to fetch child list: ");
203 scanf("%s", parent_mailbox);
207 if(strcmp(parent_mailbox, "0") != 0) {
208 testapp_print("\ninput : %s\n", parent_mailbox);
209 parent_mailbox_pointer = parent_mailbox;
212 if( (err_code = email_get_child_mailbox_list(account_id,parent_mailbox_pointer, &mailbox_list, &count)) < 0) {
213 testapp_print(" email_get_child_mailbox_list error : %d\n",err_code);
217 testapp_print("There are %d mailboxes\n", count);
219 testapp_print("============================================================================\n");
220 testapp_print("number\taccount_id\t name\t alias\t local_yn\t unread\t mailbox_type\thas_archived_mails\n");
221 testapp_print("============================================================================\n");
223 testapp_print("No mailbox is matched\n");
228 testapp_print("[%d] - ", i);
229 testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
230 testapp_print(" %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count,mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
233 testapp_print("============================================================================\n");
235 email_free_mailbox(&mailbox_list, count);
239 static gboolean testapp_test_get_mailbox_by_type ()
243 int i = 0, err_code = EMF_ERROR_NONE;
244 emf_mailbox_t *mailbox =NULL;
245 emf_mailbox_type_e mailbox_type =0;
247 testapp_print("\n > Enter account id: ");
248 scanf("%d", &account_id);
250 testapp_print("\n > Enter mailbox_type: ");
251 scanf("%d", (int*)&mailbox_type);
253 if( (err_code = email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox)) < 0) {
254 testapp_print(" email_get_mailbox_by_mailbox_type error : %d\n",err_code);
258 testapp_print("============================================================================\n");
259 testapp_print("number\taccount_id\t name\t alias\t local_yn\t unread\t mailbox_type\thas_archived_mails\n");
260 testapp_print("============================================================================\n");
262 testapp_print("[%d] - ", i);
263 testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox->account_id, mailbox->name, mailbox->alias);
264 testapp_print(" %d\t %d\t %d\n", mailbox->local, mailbox->unread_count,mailbox->mailbox_type, mailbox->has_archived_mails);
266 testapp_print("============================================================================\n");
268 email_free_mailbox(&mailbox, 1);
272 static gboolean testapp_test_set_mail_slot_size ()
275 int account_id = 0, mail_slot_size = 0;
276 int err_code = EMF_ERROR_NONE;
278 char *mailbox_name = NULL;
280 testapp_print("\n > Enter account id (0: All account): ");
281 scanf("%d", &account_id);
283 memset(arg, 0x00, 500);
284 testapp_print("\n> Enter mailbox name (0 : All mailboxes):");
286 if (strcmp(arg, "0") != 0 ) {
290 testapp_print("\n > Enter mailbox slot size: ");
291 scanf("%d", &mail_slot_size);
293 if( (err_code = email_set_mail_slot_size(account_id, mailbox_name, mail_slot_size) ) < 0) {
294 testapp_print(" testapp_test_set_mail_slot_size error : %d\n", err_code);
302 static gboolean testapp_test_interpret_command (int menu_number)
304 gboolean go_to_loop = TRUE;
306 switch (menu_number) {
308 testapp_test_add_mailbox();
312 testapp_test_delete_mailbox ();
316 testapp_test_update_mailbox ();
320 testapp_test_get_imap_mailbox_list();
324 testapp_test_get_child_mailbox_list();
328 testapp_test_get_mailbox_by_type();
332 testapp_test_set_mail_slot_size();
345 void emf_test_mailbox_main()
347 gboolean go_to_loop = TRUE;
351 testapp_show_menu (EMF_MAILBOX_MENU);
352 testapp_show_prompt (EMF_MAILBOX_MENU);
354 scanf ("%d", &menu_number);
356 go_to_loop = testapp_test_interpret_command (menu_number);