2.0_alpha release commit
[framework/messaging/email-service.git] / utilities / test-application / testapp-account.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 /* common header */
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 /* open header */
28 #include <glib.h>
29
30 #include "email-api.h"
31 #include "email-api-account.h"
32 #include "email-api-network.h"
33
34 /* internal header */
35 #include "testapp-utility.h"
36 #include "testapp-account.h"
37 #include <sys/time.h>
38 #include <sys/times.h>
39
40 /* internal defines */
41
42 #define GWB_RECV_SERVER_ADDR        "pop.gawab.com"
43 #define GWB_SMTP_SERVER_ADDR        "smtp.gawab.com"
44
45 #define VDF_RECV_SERVER_ADDR  "imap.email.vodafone.de"
46 #define VDF_SMTP_SERVER_ADDR  "smtp.email.vodafone.de"
47
48 /*  SAMSUNG 3G TEST */
49 #define S3G_RECV_SERVER_ADDR                "165.213.73.235"
50 #define S3G_RECV_SERVER_PORT                EMAIL_POP3_PORT
51 #define S3G_RECV_USE_SECURITY               0
52 #define S3G_RECV_IMAP_USE_SECURITY      1
53 #define S3G_SMTP_SERVER_ADDR                "165.213.73.235"
54 #define S3G_SMTP_SERVER_PORT                465
55 #define S3G_SMTP_AUTH                                   1
56 #define S3G_SMTP_USE_SECURITY         1
57 #define S3G_KEEP_ON_SERVER                    1
58
59 gboolean testapp_test_create_account_by_account_type(int account_type,int *account_id) 
60 {
61         email_account_t *account = NULL;
62         char id_string[100] = { 0, }, password_string[100] = { 0, }, address_string[100]  = { 0, };
63         int err_code = EMAIL_ERROR_NONE, samsung3g_account_index;
64         int result_from_scanf = 0;
65         unsigned handle;
66
67         switch(account_type) {
68                 case 4 : 
69                 case 5 :
70                         do {
71                                 testapp_print("Enter your account index [1~10] : ");
72                                 result_from_scanf = scanf("%d",&samsung3g_account_index);
73                         }while( samsung3g_account_index > 10 || samsung3g_account_index < 1);
74                         sprintf(id_string, "test%02d", samsung3g_account_index);
75                         sprintf(address_string, "<test%02d@streaming.s3glab.net>", samsung3g_account_index);
76                         strcpy(password_string, id_string);
77                         break;
78                 default:
79                         testapp_print("Enter email address : ");
80                         result_from_scanf = scanf("%s", address_string);
81
82                         testapp_print("Enter id : ");
83                         result_from_scanf = scanf("%s", id_string);
84
85                         testapp_print("Enter password_string : ");
86                         result_from_scanf = scanf("%s", password_string);
87                         break;
88         }
89
90         account = malloc(sizeof(email_account_t));
91         memset(account, 0x00, sizeof(email_account_t));
92
93         typedef struct {
94                 int is_preset_account;
95                 int index_color;
96         } user_data_t;
97         user_data_t data = (user_data_t) {1, 0};
98         /* if user_data_t has any pointer member, please don't use sizeof(). */
99         /* You need to serialize user_data to buffer and then take its length */
100         int data_length = sizeof(data);
101
102         /* Common Options */
103         account->retrieval_mode                = EMAIL_IMAP4_RETRIEVAL_MODE_ALL;
104         account->incoming_server_secure_connection      = 1;
105         account->outgoing_server_type          = EMAIL_SERVER_TYPE_SMTP;
106         account->auto_download_size                        = 2;
107         account->outgoing_server_use_same_authenticator = 1;
108         account->pop_before_smtp               = 0;
109         account->incoming_server_requires_apop = 0;
110         account->logo_icon_path                = NULL;
111         account->user_data                     = malloc (data_length);
112         memcpy( account->user_data, (void*) &data, data_length );
113         account->user_data_length              = data_length;
114         account->options.priority              = 3;
115         account->options.keep_local_copy       = 0;
116         account->options.req_delivery_receipt  = 0;
117         account->options.req_read_receipt      = 0;
118         account->options.download_limit        = 0;
119         account->options.block_address         = 0;
120         account->options.block_subject         = 0;
121         account->options.display_name_from     = NULL;
122         account->options.reply_with_body       = 0;
123         account->options.forward_with_files    = 0;
124         account->options.add_myname_card       = 0;
125         account->options.add_signature         = 0;
126         account->options.signature             = NULL;
127         account->options.add_my_address_to_bcc = 0;
128         account->check_interval                = 0;
129         account->keep_mails_on_pop_server_after_download        = 1;
130         account->default_mail_slot_size        = 200;
131
132         account->account_name                  = strdup(address_string);
133         account->user_display_name             = strdup(id_string);
134         account->user_email_address            = strdup(address_string);
135         account->reply_to_address              = strdup(address_string);
136         account->return_address                = strdup(address_string);
137
138         account->incoming_server_user_name     = strdup(id_string);
139         account->incoming_server_password      = strdup(password_string);
140         account->outgoing_server_user_name     = strdup(id_string);
141         account->outgoing_server_password          = strdup(password_string);
142
143         switch (account_type) {
144                 case 1:/*  gawab */
145                         account->incoming_server_type            = EMAIL_SERVER_TYPE_POP3 ;
146                         account->incoming_server_address         = strdup(GWB_RECV_SERVER_ADDR);
147                         account->incoming_server_port_number = EMAIL_POP3S_PORT;
148                         account->outgoing_server_address     = strdup(GWB_SMTP_SERVER_ADDR);
149                         account->incoming_server_secure_connection      = 1;
150                         account->outgoing_server_need_authentication = 1;
151                         account->outgoing_server_port_number = EMAIL_SMTPS_PORT;
152                         account->outgoing_server_secure_connection       = 1;
153
154                         break;
155
156                 case 2:/*  vadofone */
157                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
158                         account->incoming_server_address= strdup(VDF_RECV_SERVER_ADDR);
159                         account->incoming_server_port_number = EMAIL_IMAP_PORT;
160                         account->outgoing_server_address     = strdup(VDF_SMTP_SERVER_ADDR);
161                         account->incoming_server_secure_connection      = 0;
162                         account->outgoing_server_need_authentication = 0;
163                         break;
164
165                 case 4:/*  SAMSUNG 3G TEST */
166                         account->incoming_server_type            = EMAIL_SERVER_TYPE_POP3;
167                         account->incoming_server_address         = strdup(S3G_RECV_SERVER_ADDR);
168                         account->incoming_server_port_number = S3G_RECV_SERVER_PORT;
169                         account->outgoing_server_address     = strdup(S3G_SMTP_SERVER_ADDR);
170                         account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT;
171                         account->incoming_server_secure_connection      = S3G_RECV_USE_SECURITY;
172                         account->outgoing_server_secure_connection  = S3G_SMTP_USE_SECURITY;
173                         account->outgoing_server_need_authentication = S3G_SMTP_AUTH;
174                         break;
175
176                 case 5:/*  SAMSUNG 3G TEST */
177                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
178                         account->incoming_server_address= strdup(S3G_RECV_SERVER_ADDR);
179                         account->incoming_server_port_number = EMAIL_IMAPS_PORT;
180                         account->outgoing_server_address     = strdup(S3G_SMTP_SERVER_ADDR);
181                         account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT;
182                         account->incoming_server_secure_connection      = 1;
183                         account->outgoing_server_secure_connection  = S3G_SMTP_USE_SECURITY;
184                         account->outgoing_server_need_authentication = S3G_SMTP_AUTH;
185                         break;
186
187                 case 6:/*  Gmail POP3 */
188                         account->incoming_server_type  = EMAIL_SERVER_TYPE_POP3;
189                         account->incoming_server_address= strdup("pop.gmail.com");
190                         account->incoming_server_port_number = 995;
191                         account->incoming_server_secure_connection      = 1;
192                         account->outgoing_server_address    = strdup("smtp.gmail.com");
193                         account->outgoing_server_port_number = 465;
194                         account->outgoing_server_secure_connection = 1;
195                         account->outgoing_server_need_authentication = 1;
196                         break;
197
198                 case 7 : /*  Gmail IMAP4 */
199                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
200                         account->incoming_server_address= strdup("imap.gmail.com");
201                         account->incoming_server_port_number = 993;
202                         account->incoming_server_secure_connection      = 1;
203                         account->outgoing_server_address    = strdup("smtp.gmail.com");
204                         account->outgoing_server_port_number = 465;
205                         account->outgoing_server_secure_connection = 1;
206                         account->outgoing_server_need_authentication = 1;
207                         break;
208
209                 case 8: /*  Active Sync */
210                         account->incoming_server_type  = EMAIL_SERVER_TYPE_ACTIVE_SYNC;
211                         account->incoming_server_address= strdup("");
212                         account->incoming_server_port_number = 0;
213                         account->incoming_server_secure_connection      = 1;
214                         account->outgoing_server_address    = strdup("");
215                         account->outgoing_server_port_number = 0;
216                         account->outgoing_server_secure_connection = 1;
217                         account->outgoing_server_need_authentication = 1;
218                         break;
219
220                 case 9: /*  AOL */
221                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
222                         account->incoming_server_address= strdup("imap.aol.com");
223                         account->incoming_server_port_number = 143;
224                         account->incoming_server_secure_connection      = 0;
225                         account->outgoing_server_address    = strdup("smtp.aol.com");
226                         account->outgoing_server_port_number = 587;
227                         account->outgoing_server_secure_connection = 0;
228                         account->outgoing_server_need_authentication = 1;
229                         break;
230
231                 case 10: /*  Hotmail */
232                         account->incoming_server_type  = EMAIL_SERVER_TYPE_POP3;
233                         account->incoming_server_address= strdup("pop3.live.com");
234                         account->incoming_server_port_number = 995;
235                         account->incoming_server_secure_connection      = 1;
236                         account->outgoing_server_address    = strdup("smtp.live.com");
237                         account->outgoing_server_port_number = 587;
238                         account->outgoing_server_secure_connection  = 0x02;
239                         account->outgoing_server_need_authentication = 1;
240                         break;
241
242                 case 11:/*  Daum IMAP4*/
243                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
244                         account->incoming_server_address= strdup("imap.daum.net");
245                         account->incoming_server_port_number = 993;
246                         account->incoming_server_secure_connection      = 1;
247                         account->outgoing_server_address    = strdup("smtp.daum.net");
248                         account->outgoing_server_port_number = 465;
249             account->outgoing_server_secure_connection = 1;
250                         account->outgoing_server_need_authentication = 1;
251                         break;
252
253                 case 12:/*  Daum POP3*/
254                         account->incoming_server_type  = EMAIL_SERVER_TYPE_POP3;
255                         account->incoming_server_address= strdup("pop.daum.net");
256                         account->incoming_server_port_number = 995;
257                         account->incoming_server_secure_connection      = 1;
258                         account->outgoing_server_address    = strdup("smtp.daum.net");
259                         account->outgoing_server_port_number = 465;
260             account->outgoing_server_secure_connection = 1;
261                         account->outgoing_server_need_authentication = 1;
262                         break;
263
264                 default:
265                         testapp_print("Invalid Account Number\n");
266                         return FALSE;
267                         break;
268         }
269         account->account_svc_id = 77;
270         err_code = email_add_account_with_validation(account, &handle);
271         if( err_code < 0) {
272                 testapp_print ("   email_add_account_with_validation error : %d\n",err_code);
273                 return FALSE;
274         }
275
276         testapp_print ("   email_add_account succeed\n");
277
278         if(account_id)
279                 *account_id = account->account_id;
280
281         err_code = email_free_account(&account, 1);
282         return TRUE;
283
284 }
285
286 static gboolean testapp_test_create_account() 
287 {
288         int account_type = 0 ;
289         int err = EMAIL_ERROR_NONE;
290         int result_from_scanf = 0;
291         
292         testapp_print("1. Gawab\n");
293         testapp_print("2. Vodafone\n");
294         testapp_print("4. SAMSUNG 3G TEST (POP)\n");
295         testapp_print("5. SAMSUNG 3G TEST (IMAP)\n");
296         testapp_print("6. Gmail (POP3)\n");
297         testapp_print("7. Gmail (IMAP4)\n");
298         testapp_print("8. Active Sync (dummy)\n");
299         testapp_print("9. AOL\n");
300         testapp_print("10. Hotmail\n");
301         testapp_print("11. Daum (IMAP4)\n");
302         testapp_print("12. Daum (POP3)\n");
303         testapp_print("Choose server type: ");
304         
305         result_from_scanf = scanf("%d",&account_type);
306
307         if(!testapp_test_create_account_by_account_type(account_type,&err)) {
308                 testapp_print ("   testapp_test_create_account_by_account_type error\n");
309                 return FALSE;
310         }
311         return FALSE;
312 }
313
314 static gboolean testapp_test_update_account()
315 {
316         int result_from_scanf = 0;
317         int account_id;
318         email_account_t *account = NULL;
319         char account_name[256];
320         int err = EMAIL_ERROR_NONE;
321         char signature[100] = {0};
322         char user_email_address[256] = {0,};
323         int add_my_address_to_bcc = 0;
324         int account_svc_id = 0, with_validation = 0;
325
326         
327         testapp_print("\n>> Enter Account No: ");
328         result_from_scanf = scanf("%d",&account_id);
329
330 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
331         if( (err = email_get_account(account_id, GET_FULL_DATA,&account)) != EMAIL_ERROR_NONE) {
332                 testapp_print ("email_get_account failed - %d\n", err);
333                 return false;
334         }
335
336         testapp_print ("email_get_account result account_name - %s \n", account->account_name);
337
338         testapp_print ("email_get_account result signature - %s \n", account->options.signature);
339
340 #ifdef __FEATURE_AUTO_POLLING__
341         testapp_print ("email_get_account result check_interval - %d \n", account->check_interval);
342 #endif
343
344         testapp_print("\n Enter new Account name:");
345         result_from_scanf = scanf("%s",account_name);
346
347         
348         testapp_print("\n Enter new email addr:");
349         result_from_scanf = scanf("%s",user_email_address);
350 #ifdef __FEATURE_AUTO_POLLING__
351         testapp_print("\n Enter new check interval (in mins):");
352         result_from_scanf = scanf("%d",&(account->check_interval));
353 #endif
354         testapp_print("\n Enter new signature:");
355         result_from_scanf = scanf("%s",signature);
356
357         testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) ");
358         result_from_scanf = scanf("%d",&add_my_address_to_bcc);
359
360         testapp_print("\n>> Enter account_svc_id: ");
361         result_from_scanf = scanf("%d",&account_svc_id);
362
363         testapp_print("\n>> With validation ? (0: No, 1:Yes) ");
364         result_from_scanf = scanf("%d",&with_validation);
365
366     if( account )  {
367                 account->account_name = strdup(account_name);
368                 testapp_print("\n Assigning New Account name: (%s)", account->account_name);
369                 account->user_email_address = strdup(user_email_address);
370                 account->options.signature = strdup(signature);
371                 testapp_print("\n Assigning New Signature: (%s)\n", account->options.signature);
372                 account->options.add_my_address_to_bcc = add_my_address_to_bcc;
373                 account->account_svc_id = account_svc_id;
374
375                 if(with_validation) {
376                         if((err = email_update_account_with_validation(account_id, account)) != EMAIL_ERROR_NONE){
377                                 testapp_print ("email_update_account_with_validation failed - %d\n", err);
378                                 return false;
379                         }
380                                 testapp_print ("email_update_account_with_validation successful \n");
381                 }
382                 else {
383                         if((err = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) {
384                                 testapp_print ("email_update_account failed - %d\n", err);
385                                 return false;
386                         }
387                         testapp_print ("email_update_account successful \n");
388                 }
389     }
390         return true;
391 }
392
393 static gboolean testapp_test_delete_account ()
394 {
395         int account_id;
396         email_account_t *account=NULL;
397         int err = EMAIL_ERROR_NONE;
398         int result_from_scanf = 0;
399
400         testapp_print("\n>> Enter Account No: ");
401         result_from_scanf = scanf("%d",&account_id);
402
403 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
404         if( (err = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0) {
405                 testapp_print ("email_get_account failed \n");
406                 testapp_print("testapp_test_delete_account failed\n");
407         }
408         else {
409                 testapp_print ("email_get_account result account_name - %s \n", account->account_name);
410
411                 if((err = email_delete_account(account_id)) < 0) 
412                         testapp_print ("email_delete_account failed[%d]\n", err);
413                 else
414                         testapp_print ("email_delete_account successful \n");
415         }
416         return FALSE;
417
418 }
419
420
421 static gboolean testapp_test_validate_account ()
422 {
423         int result_from_scanf = 0;
424         int account_id;
425         email_account_t *account=NULL;
426         int err_code = EMAIL_ERROR_NONE;
427         unsigned account_handle = 0;
428         
429         testapp_print("\n>> Enter Account No: ");
430         result_from_scanf = scanf("%d",&account_id);
431
432 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
433         if( (err_code = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0 ) {
434                 testapp_print ("email_get_account failed \n");
435                 return FALSE;
436         }
437         else
438                 testapp_print ("email_get_account result account_name - %s \n", account->account_name);
439
440         if((err_code = email_validate_account(account_id, &account_handle)) == EMAIL_ERROR_NONE ) 
441                 testapp_print ("email_validate_account successful  account_handle : %u\n",account_handle);
442         else
443                 testapp_print ("email_validate_account failed err_code: %d \n",err_code);
444                 
445         return FALSE;
446
447 }
448
449
450 static gboolean testapp_test_cancel_validate_account ()
451 {
452         int result_from_scanf = 0;
453         int account_id = 0;
454         int err_code = EMAIL_ERROR_NONE;
455         unsigned account_handle = 0;
456
457         testapp_print("\n > Enter account_id: ");
458         result_from_scanf = scanf("%d", &account_id);
459
460         testapp_print("\n > Enter handle: ");
461         result_from_scanf = scanf("%d", &account_handle);
462
463         err_code = email_cancel_job(account_id, account_handle, EMAIL_CANCELED_BY_USER);
464         if(err_code == 0)
465                 testapp_print("email_cancel_job Success..!handle:[%d]", account_handle);
466         else
467                 testapp_print ("email_cancel_job failed err_code: %d \n",err_code);
468         
469         return FALSE;
470 }
471
472 static gboolean testapp_test_get_account()
473 {
474         int result_from_scanf = 0;
475         int account_id;
476         email_account_t *account=NULL;
477         int err_code = EMAIL_ERROR_NONE;
478         testapp_print("\n>> Enter Account No: ");
479         result_from_scanf = scanf("%d",&account_id);
480
481         typedef struct {
482                 int is_preset_account;
483                 int index_color;
484         } user_data_t;
485
486         testapp_print ("\n----------------------------------------------------------\n");
487         testapp_print ("email_get_account GET_FULL_DATA \n");
488         if( (err_code = email_get_account(account_id,GET_FULL_DATA,&account)) < 0) {
489                 testapp_print ("email_get_account failed - %d\n", err_code);
490                 return FALSE;
491         }
492
493         user_data_t* val = (user_data_t*) account->user_data;
494         int is_preset_account =  val? val->is_preset_account : 0;
495         int index_color = val? val->index_color : 0;
496
497         testapp_print ("email_get_account result\n"
498                         "account_name - %s \n"
499                         "user_email_address - %s \n"
500                         "incoming_server_secure_connection %d \n"
501                         "add_sig : %d \n"
502                         "signature %s \n"
503                         "add_my_address_to_bcc %d \n"
504                         "account_svc_id %d\n"
505                         "incoming_server_address %s\n"
506                         "outgoing_server_address %s\n"
507                         "default_mail_slot_size %d\n"
508                         "sync_status %d\n"
509                         "sync_disabled %d\n"
510                         "is_preset %d\n"
511                         "index_color %d\n"
512                         "certificate_path %s\n"
513                         "digest_type %d\n"
514                 ,
515                 account->account_name,
516                 account->user_email_address,
517                 account->incoming_server_secure_connection,
518                 account->options.add_signature,
519                 account->options.signature,
520                 account->options.add_my_address_to_bcc,
521                 account->account_svc_id,
522                 account->incoming_server_address,
523                 account->outgoing_server_address,
524                 account->default_mail_slot_size,
525                 account->sync_status,
526                 account->sync_disabled,
527                 is_preset_account,
528                 index_color,
529                 account->certificate_path,
530                 account->digest_type
531                 );
532
533         err_code = email_free_account(&account, 1);
534
535         testapp_print ("\n----------------------------------------------------------\n");
536         testapp_print ("email_get_account WITHOUT_OPTION \n");
537
538         if( (err_code = email_get_account(account_id, WITHOUT_OPTION, &account)) < 0) {
539                 testapp_print ("email_get_account failed \n");
540                 return FALSE;
541         }
542
543         testapp_print ("email_get_account result\n"
544                         "account_name - %s \n"
545                         "user_email_address - %s \n"
546                         "incoming_server_secure_connection %d \n"
547                         "add_signature : %d \n",
548                 account->account_name,
549                 account->user_email_address,
550                 account->incoming_server_secure_connection,
551                 account->options.add_signature
552         );
553
554         if(account->options.signature)
555                 testapp_print ("signature : %s\n", account->options.signature);
556         else
557                 testapp_print ("signature not retrieved \n");
558
559         err_code = email_free_account(&account, 1);
560
561         testapp_print ("\n----------------------------------------------------------\n");
562         testapp_print ("email_get_account ONLY_OPTION \n");
563
564         if( (err_code = email_get_account(account_id, ONLY_OPTION, &account)) < 0) {
565                 testapp_print ("email_get_account failed \n");
566                 return FALSE;
567         }
568
569         testapp_print ("email_get_account result\n"
570                         "add_sig : %d \n"
571                         "signature %s \n"
572                         "add_my_address_to_bcc %d\n"
573                         "account_svc_id %d\n",
574                 account->options.add_signature,
575                 account->options.signature,
576                 account->options.add_my_address_to_bcc,
577                 account->account_svc_id
578                 );
579
580         if(account->account_name)
581                 testapp_print ("account_name : %s \n", account->account_name);
582         else
583                 testapp_print ("account_name not retrieved \n");        
584
585         if(account->user_email_address)
586                 testapp_print ("user_email_address : %s \n", account->user_email_address);
587         else
588                 testapp_print ("user_email_address not retrieved \n");  
589         err_code = email_free_account(&account, 1);
590                 
591         return FALSE;
592 }
593
594 static gboolean testapp_test_get_account_list ()
595 {
596
597         int count, i;
598         email_account_t *account_list=NULL;
599         struct timeval tv_1, tv_2;
600         int interval;
601         int err_code = EMAIL_ERROR_NONE;
602
603         gettimeofday(&tv_1, NULL);
604
605         if((err_code = email_get_account_list(&account_list, &count)) < 0 ) {
606                 testapp_print("   email_get_account_list error\n");
607                 return false ;
608         }
609
610         gettimeofday(&tv_2, NULL);
611         interval = tv_2.tv_usec - tv_1.tv_usec;
612         testapp_print("\t testapp_test_get_account_list Proceed time %d us\n",interval);
613         
614         for(i=0;i<count;i++){
615                 testapp_print("   %2d) %-15s %-30s\n",account_list[i].account_id, 
616                         account_list[i].account_name, 
617                         account_list[i].user_email_address);
618         }
619
620         err_code = email_free_account(&account_list, count);
621         return FALSE;
622 }
623
624 static gboolean testapp_test_backup_account()
625 {
626         char *file_name = "accounts_file";
627         int error_code;
628         error_code = email_backup_accounts_into_secure_storage(file_name);
629         testapp_print("\n email_backup_accounts_into_secure_storage returned [%d]\n",error_code);
630         return FALSE;
631 }
632 static gboolean testapp_test_restore_account()
633 {
634         char *file_name = "accounts_file";
635         int error_code;
636         error_code = email_restore_accounts_from_secure_storage(file_name);
637         testapp_print("\n email_restore_accounts_from_secure_storage returned [%d]\n",error_code);
638         return FALSE;
639 }
640
641 static gboolean testapp_test_get_password_length_of_account()
642 {
643         int result_from_scanf = 0;
644         int error_code, password_length, account_id;
645
646         testapp_print("\n input account id\n");
647         result_from_scanf = scanf("%d", &account_id);
648         error_code = email_get_password_length_of_account(account_id, &password_length);
649         testapp_print("testapp_test_get_password_length_of_account returned [%d]\n",password_length);
650         return FALSE;
651 }
652
653 static gboolean testapp_test_query_server_info()
654 {
655         int result_from_scanf = 0;
656         int error_code;
657         char domain_name[255];
658         email_server_info_t *result_server_info;
659
660         testapp_print("\n input domain name\n");
661         result_from_scanf = scanf("%s", domain_name);
662
663         error_code = email_query_server_info(domain_name, &result_server_info);
664         testapp_print("email_query_server_info returned [%d]\n",error_code);
665         if(error_code == EMAIL_ERROR_NONE)
666                 testapp_print("service_name [%s]\n", result_server_info->service_name);
667         return FALSE;
668 }
669
670 static gboolean testapp_test_clear_all_notification()
671 {
672         int error_code;
673
674         error_code = email_clear_all_notification_bar();
675         testapp_print("email_clear_all_notification_bar returned [%d]\n",error_code);
676         return FALSE;
677 }
678
679 static gboolean testapp_test_save_default_account_id()
680 {
681         int result_from_scanf = 0;
682         int error_code;
683         int account_id = 0;
684
685         testapp_print ("\nInput default account id : ");
686
687         result_from_scanf = scanf("%d", &account_id);
688
689         error_code = email_save_default_account_id(account_id);
690
691         testapp_print("email_save_default_account_id returned [%d]\n",error_code);
692         return FALSE;
693 }
694
695 static gboolean testapp_test_load_default_account_id()
696 {
697         int error_code;
698         int account_id = 0;
699
700         error_code = email_load_default_account_id(&account_id);
701
702         testapp_print ("\ndefault account id : %d\n", account_id);
703         testapp_print("email_load_default_account_id returned [%d]\n",error_code);
704         return FALSE;
705 }
706
707 static gboolean testapp_test_add_certificate()
708 {
709         int result_from_scanf = 0;
710         int ret = 0;
711         char save_name[50] = {0, };
712         char certificate_path[255] = {0, };
713
714         testapp_print("Input cert path : ");
715         result_from_scanf = scanf("%s", certificate_path);      
716
717         testapp_print("Input cert email-address : ");
718         result_from_scanf = scanf("%s", save_name);
719
720         testapp_print("cert path : [%s]", certificate_path);
721         testapp_print("email-address : [%s]", save_name);
722
723         ret = email_add_certificate(certificate_path, save_name);
724         if (ret != EMAIL_ERROR_NONE) {
725                 testapp_print("Add certificate failed\n");
726                 return false;
727         }
728
729         testapp_print("Add certificate success\n");
730         return true;
731 }
732
733 static gboolean testapp_test_get_certificate()
734 {
735         int result_from_scanf = 0;
736         int ret = 0;
737         char save_name[20] = {0, };
738         email_certificate_t *certificate = NULL;
739
740         testapp_print("Input cert email-address : ");
741         result_from_scanf = scanf("%s", save_name);
742
743         ret = email_get_certificate(save_name, &certificate);
744         if (ret != EMAIL_ERROR_NONE) {
745                 testapp_print("Get certificate failed\n");
746                 return false;
747         }
748
749         testapp_print("certificate_id : %d\n", certificate->certificate_id);
750         testapp_print("issue_year : %d\n", certificate->issue_year);
751         testapp_print("issue_month : %d\n", certificate->issue_month);
752         testapp_print("issue_day : %d\n", certificate->issue_day);
753         testapp_print("expiration_year : %d\n", certificate->expiration_year);
754         testapp_print("expiration_month : %d\n", certificate->expiration_month);
755         testapp_print("expiration_day : %d\n", certificate->expiration_day);
756         testapp_print("issue_organization_name : %s\n", certificate->issue_organization_name);
757         testapp_print("subject_string : %s\n", certificate->subject_str);
758         testapp_print("file path : %s\n", certificate->filepath);
759
760         if (certificate)
761                 email_free_certificate(&certificate, 1);
762
763         testapp_print("Get certificate success\n");
764         return true;
765 }
766
767 static gboolean testapp_test_delete_certificate()
768 {
769         int result_from_scanf = 0;
770         int ret = 0;
771         char save_name[20] = {0, };
772
773         testapp_print("Input cert email-address : ");
774         result_from_scanf = scanf("%s", save_name);
775
776         ret = email_delete_certificate(save_name);
777         if (ret != EMAIL_ERROR_NONE) {
778                 testapp_print("Delete certificate failed\n");
779                 return false;
780         }
781
782         testapp_print("Delete certificate success\n");
783         return true;
784 }
785 static gboolean testapp_test_interpret_command (int selected_number)
786 {
787         gboolean go_to_loop = TRUE;
788         
789         switch (selected_number) {
790                 case 1:
791                         testapp_test_create_account();
792                         break;
793
794                 case 2:
795                         testapp_test_update_account();
796                         break;
797
798                 case 3:
799                         testapp_test_delete_account();
800                         break;
801
802                 case 4:
803                         testapp_test_get_account();
804                         break;
805                 
806                 case 5:
807                         testapp_test_get_account_list();
808                         break;
809
810                 case 7:
811                         testapp_test_validate_account();
812                         break;          
813
814                 case 8:
815                         testapp_test_cancel_validate_account();
816                         break;  
817
818                 case 9:
819                         testapp_test_backup_account();
820                         break;  
821
822                 case 10:
823                         testapp_test_restore_account();
824                         break;  
825
826                 case 11:
827                         testapp_test_get_password_length_of_account();
828                         break;
829
830                 case 12:
831                         testapp_test_query_server_info();
832                         break;
833
834                 case 13:
835                         testapp_test_clear_all_notification();
836                         break;
837
838                 case 14:
839                         testapp_test_save_default_account_id();
840                         break;
841
842                 case 15:
843                         testapp_test_load_default_account_id();
844                         break;
845
846                 case 16:
847                         testapp_test_add_certificate();
848                         break;
849
850                 case 17:
851                         testapp_test_get_certificate();
852                         break;
853
854                 case 18:
855                         testapp_test_delete_certificate();
856                         break;
857
858                 case 0:
859                         go_to_loop = FALSE;
860                         break;
861
862                 default:
863                         break;
864         }
865
866         return go_to_loop;
867 }
868
869 void testapp_account_main ()
870 {
871         gboolean go_to_loop = TRUE;
872         int menu_number = 0;
873         int result_from_scanf = 0;
874         
875         while (go_to_loop) {
876                 testapp_show_menu (EMAIL_ACCOUNT_MENU);
877                 testapp_show_prompt (EMAIL_ACCOUNT_MENU);
878                         
879                 result_from_scanf = scanf ("%d", &menu_number);
880
881                 go_to_loop = testapp_test_interpret_command (menu_number);
882         }       
883 }
884