tizen beta release
[framework/messaging/email-service.git] / utilities / email-service-test-application / email-service-test-application / emf-test-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 /* common header */
25 #include <stdio.h>
26 #include <string.h>
27
28
29 /* open header */
30 #include <glib.h>
31
32 #include "Emf_Mapi_Message.h"
33 #include "Emf_Mapi_Network.h"
34 #include "Emf_Mapi_Mailbox.h"
35
36 /* internal header */
37 #include "emf-test-utility.h"
38 #include "emf-test-mailbox.h"
39
40
41 static gboolean testapp_test_add_mailbox()
42 {
43         emf_mailbox_t  mbox;
44         int account_id,mailbox_type = 0;
45         int local_yn = 0;
46         char arg[500];
47         int ret;
48     unsigned handle;
49
50         memset(arg, 0x00, 500);
51         testapp_print("\n> Enter mailbox name: ");
52         scanf("%s",arg);
53         mbox.name = strdup(arg);
54         
55         memset(arg, 0x00, 500);
56         testapp_print("> Enter mailbox alias name: ");
57         scanf("%s",arg);
58         mbox.alias = strdup(arg);
59
60         testapp_print("> Enter account id: ");
61         scanf("%d", &account_id);
62         mbox.account_id = account_id;
63
64         testapp_print("> Enter local_yn (1/0): ");
65         scanf("%d", &local_yn);
66         mbox.local= local_yn;   
67
68
69         testapp_print("> Enter mailbox type: ");
70         scanf("%d", &mailbox_type);
71         mbox.mailbox_type= mailbox_type;
72
73         ret = email_add_mailbox(&mbox, local_yn?0:1, &handle);
74
75         if (ret  < 0) {
76                 testapp_print("\n email_add_mailbox failed");
77         }
78         else {
79                 testapp_print("\n email_add_mailbox succeed : handle[%d]\n", handle);
80         }
81         
82         return FALSE;
83 }
84
85 static gboolean testapp_test_delete_mailbox()
86 {
87
88         emf_mailbox_t  mbox;
89         int account_id;
90         int local_yn = 0;
91         char arg[500];
92         int ret;
93         unsigned handle;
94
95         memset(arg, 0x00, 500);
96         testapp_print("\n> Enter mailbox name:");
97         scanf("%s",arg);
98         mbox.name = strdup(arg);
99         
100         testapp_print("> Enter account id: ");
101         scanf("%d", &account_id);
102         mbox.account_id = account_id;
103
104         testapp_print("> Enter local_yn (1/0): ");
105         scanf("%d", &local_yn);
106
107         ret = email_delete_mailbox(&mbox, local_yn?0:1, &handle);
108
109         if ( ret < 0) {
110                 testapp_print("\n email_delete_mailbox failed");
111         }
112         else {
113                 testapp_print("\n email_delete_mailbox succeed : handle[%d]\n", handle);
114         }
115         
116         return FALSE;
117
118 }
119
120 static gboolean testapp_test_update_mailbox()
121 {
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;
126         char arg[500];
127         int err;
128
129         memset(arg, 0x00, 500);
130         
131         testapp_print("> Enter account id: ");
132         scanf("%d", &account_id);
133
134         testapp_print("\n> Enter mailbox name: ");
135         scanf("%s", arg);
136         
137         testapp_print("> Enter mailbox type: ");
138         scanf("%d", &mailbox_type);
139
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);
143         }
144         else {
145                 testapp_print("\n email_get_mailbox_by_name succeed\n");
146         }
147         
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);
151         }
152         else {
153                 testapp_print("\n email_get_mailbox_by_name succeed\n");
154         }
155         
156         /*  set new value of new mailbox */
157         new_mbox->mailbox_type= mailbox_type;
158         
159         if ( (err = email_update_mailbox(old_mailbox_name, new_mbox)) < 0) {
160                 testapp_print("\n email_update_mailbox failed[%d]\n", err);
161         }
162         else {
163                 testapp_print("\n email_update_mailbox succeed\n");
164         }
165
166         email_free_mailbox(&old_mailbox_name, 1);
167         email_free_mailbox(&new_mbox, 1);
168
169         return FALSE;
170 }
171
172 static gboolean testapp_test_get_imap_mailbox_list()
173 {
174         int account_id = 0;
175         unsigned handle = 0;
176         
177         testapp_print("> Enter account id: ");
178         scanf("%d", &account_id);       
179         
180         if(  email_get_imap_mailbox_list(account_id, "", &handle) < 0)
181                 testapp_print("email_get_imap_mailbox_list failed");
182
183         return FALSE;
184
185 }
186
187 static gboolean testapp_test_get_child_mailbox_list ()
188 {
189
190         int account_id =0;
191         int count = 0;
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;
195
196         
197         memset(parent_mailbox,0x00,sizeof(parent_mailbox));
198         
199         testapp_print("\n > Enter account id: ");
200         scanf("%d", &account_id);
201
202         testapp_print("\n > Enter parent mailbox name to fetch child list: ");
203         scanf("%s", parent_mailbox);
204
205         
206
207         if(strcmp(parent_mailbox, "0") != 0) {
208                 testapp_print("\ninput : %s\n", parent_mailbox);
209                 parent_mailbox_pointer = parent_mailbox;
210         }
211
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);
214                 return false ;
215         }
216
217         testapp_print("There are %d mailboxes\n", count);
218
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");
222         if(count == 0) {
223                 testapp_print("No mailbox is matched\n");
224         }
225         else {
226                 for(i=0;i<count;i++)
227                 {
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);
231                 }
232         }
233         testapp_print("============================================================================\n");
234         
235         email_free_mailbox(&mailbox_list, count);
236         return FALSE;
237 }
238
239 static gboolean testapp_test_get_mailbox_by_type ()
240 {
241
242         int account_id =0;      
243         int i = 0, err_code = EMF_ERROR_NONE;
244         emf_mailbox_t *mailbox =NULL;
245         emf_mailbox_type_e mailbox_type =0;
246         
247         testapp_print("\n > Enter account id: ");
248         scanf("%d", &account_id);
249
250         testapp_print("\n > Enter mailbox_type: ");
251         scanf("%d", (int*)&mailbox_type);
252
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);
255                 return false ;
256         }
257
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");
261         
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);
265                 
266         testapp_print("============================================================================\n");
267         
268         email_free_mailbox(&mailbox, 1);
269         return FALSE;
270 }
271
272 static gboolean testapp_test_set_mail_slot_size ()
273 {
274
275         int account_id = 0, mail_slot_size = 0; 
276         int err_code = EMF_ERROR_NONE;
277         char arg[500];
278         char *mailbox_name = NULL;
279         
280         testapp_print("\n > Enter account id (0: All account): ");
281         scanf("%d", &account_id);
282
283         memset(arg, 0x00, 500);
284         testapp_print("\n> Enter mailbox name (0 : All mailboxes):");
285         scanf("%s",arg);
286         if (strcmp(arg, "0") != 0 ) {
287                 mailbox_name = arg;
288         }
289
290         testapp_print("\n > Enter mailbox slot size: ");
291         scanf("%d", &mail_slot_size);
292
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);
295                 return false ;
296         }
297
298         return FALSE;
299 }
300
301
302 static gboolean testapp_test_interpret_command (int menu_number)
303 {
304         gboolean go_to_loop = TRUE;
305         
306         switch (menu_number) {
307                 case 1:
308                         testapp_test_add_mailbox();
309                         break;
310
311                 case 2:
312                         testapp_test_delete_mailbox ();
313                         break;
314
315                 case 3:
316                         testapp_test_update_mailbox ();
317                         break;
318
319                 case 4:
320                         testapp_test_get_imap_mailbox_list();
321                         break;                  
322
323                 case 6:
324                         testapp_test_get_child_mailbox_list();
325                         break;  
326
327                 case 7:
328                         testapp_test_get_mailbox_by_type();
329                         break;  
330
331                 case 8:
332                         testapp_test_set_mail_slot_size();
333                         break;  
334
335                 case 0:
336                         go_to_loop = FALSE;
337                         break;
338                 default:
339                         break;
340         }
341
342         return go_to_loop;
343 }
344
345 void emf_test_mailbox_main()
346 {
347         gboolean go_to_loop = TRUE;
348         int menu_number = 0;
349         
350         while (go_to_loop) {
351                 testapp_show_menu (EMF_MAILBOX_MENU);
352                 testapp_show_prompt (EMF_MAILBOX_MENU);
353                         
354                 scanf ("%d", &menu_number);
355
356                 go_to_loop = testapp_test_interpret_command (menu_number);
357         }
358 }
359