Tizen 2.0 Release
[platform/core/messaging/email-service.git] / utilities / test-application / testapp-account.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 /* 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         int 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       = 1;
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                 case 13: /* Yahoo IMAP ID */
265                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
266                         account->incoming_server_address= strdup("samsung.imap.mail.yahoo.com");
267                         account->incoming_server_port_number = 993;
268                         account->incoming_server_secure_connection      = 1;
269                         account->outgoing_server_address    = strdup("samsung.smtp.mail.yahoo.com");
270                         account->outgoing_server_port_number = 465;
271                         account->outgoing_server_secure_connection = 1;
272                         account->outgoing_server_need_authentication = 1;
273                         break;
274
275                 default:
276                         testapp_print("Invalid Account Number\n");
277                         return FALSE;
278                         break;
279         }
280         account->account_svc_id = 77;
281         err_code = email_add_account_with_validation(account, &handle);
282         if( err_code < 0) {
283                 testapp_print ("   email_add_account_with_validation error : %d\n",err_code);
284                 err_code = email_free_account(&account, 1);
285                 return FALSE;
286         }
287
288         testapp_print ("   email_add_account succeed\n");
289
290         if(account_id)
291                 *account_id = account->account_id;
292
293         err_code = email_free_account(&account, 1);
294         return TRUE;
295
296 }
297
298 static gboolean testapp_test_create_account() 
299 {
300         int account_type = 0 ;
301         int err = EMAIL_ERROR_NONE;
302         int result_from_scanf = 0;
303         
304         testapp_print("1. Gawab\n");
305         testapp_print("2. Vodafone\n");
306         testapp_print("4. SAMSUNG 3G TEST (POP)\n");
307         testapp_print("5. SAMSUNG 3G TEST (IMAP)\n");
308         testapp_print("6. Gmail (POP3)\n");
309         testapp_print("7. Gmail (IMAP4)\n");
310         testapp_print("8. Active Sync (dummy)\n");
311         testapp_print("9. AOL\n");
312         testapp_print("10. Hotmail\n");
313         testapp_print("11. Daum (IMAP4)\n");
314         testapp_print("12. Daum (POP3)\n");
315         testapp_print("13. Yahoo (IMAP ID)\n");
316         testapp_print("Choose server type: ");
317         
318         result_from_scanf = scanf("%d",&account_type);
319
320         if(!testapp_test_create_account_by_account_type(account_type,&err)) {
321                 testapp_print ("   testapp_test_create_account_by_account_type error\n");
322                 return FALSE;
323         }
324         return FALSE;
325 }
326
327 static gboolean testapp_test_update_account()
328 {
329         int result_from_scanf = 0;
330         int account_id;
331         email_account_t *account = NULL;
332         char account_name[256];
333         int err = EMAIL_ERROR_NONE;
334         char signature[100] = {0};
335         char user_email_address[256] = {0,};
336         int add_my_address_to_bcc = 0;
337         int account_svc_id = 0, with_validation = 0;
338
339         
340         testapp_print("\n>> Enter Account No: ");
341         result_from_scanf = scanf("%d",&account_id);
342
343 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
344         if( (err = email_get_account(account_id, GET_FULL_DATA,&account)) != EMAIL_ERROR_NONE) {
345                 testapp_print ("email_get_account failed - %d\n", err);
346                 return false;
347         }
348
349         testapp_print ("email_get_account result account_name - %s \n", account->account_name);
350
351         testapp_print ("email_get_account result signature - %s \n", account->options.signature);
352
353 #ifdef __FEATURE_AUTO_POLLING__
354         testapp_print ("email_get_account result check_interval - %d \n", account->check_interval);
355 #endif
356
357         testapp_print("\n Enter new Account name:");
358         result_from_scanf = scanf("%s",account_name);
359
360         
361         testapp_print("\n Enter new email addr:");
362         result_from_scanf = scanf("%s",user_email_address);
363 #ifdef __FEATURE_AUTO_POLLING__
364         testapp_print("\n Enter new check interval (in mins):");
365         result_from_scanf = scanf("%d",&(account->check_interval));
366 #endif
367         testapp_print("\n Enter new signature:");
368         result_from_scanf = scanf("%s",signature);
369
370         testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) ");
371         result_from_scanf = scanf("%d",&add_my_address_to_bcc);
372
373         testapp_print("\n>> Enter account_svc_id: ");
374         result_from_scanf = scanf("%d",&account_svc_id);
375
376         testapp_print("\n>> With validation ? (0: No, 1:Yes) ");
377         result_from_scanf = scanf("%d",&with_validation);
378
379     if( account )  {
380                 account->account_name = strdup(account_name);
381                 testapp_print("\n Assigning New Account name: (%s)", account->account_name);
382                 account->user_email_address = strdup(user_email_address);
383                 account->options.signature = strdup(signature);
384                 testapp_print("\n Assigning New Signature: (%s)\n", account->options.signature);
385                 account->options.add_my_address_to_bcc = add_my_address_to_bcc;
386                 account->account_svc_id = account_svc_id;
387
388                 if(with_validation) {
389                         if((err = email_update_account_with_validation(account_id, account)) != EMAIL_ERROR_NONE){
390                                 testapp_print ("email_update_account_with_validation failed - %d\n", err);
391                                 return false;
392                         }
393                                 testapp_print ("email_update_account_with_validation successful \n");
394                 }
395                 else {
396                         if((err = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) {
397                                 testapp_print ("email_update_account failed - %d\n", err);
398                                 return false;
399                         }
400                         testapp_print ("email_update_account successful \n");
401                 }
402     }
403         return true;
404 }
405
406 static gboolean testapp_test_delete_account ()
407 {
408         int account_id;
409         email_account_t *account=NULL;
410         int err = EMAIL_ERROR_NONE;
411         int result_from_scanf = 0;
412
413         testapp_print("\n>> Enter Account No: ");
414         result_from_scanf = scanf("%d",&account_id);
415
416 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
417         if( (err = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0) {
418                 testapp_print ("email_get_account failed \n");
419                 testapp_print("testapp_test_delete_account failed\n");
420         }
421         else {
422                 testapp_print ("email_get_account result account_name - %s \n", account->account_name);
423
424                 if((err = email_delete_account(account_id)) < 0) 
425                         testapp_print ("email_delete_account failed[%d]\n", err);
426                 else
427                         testapp_print ("email_delete_account successful \n");
428         }
429         return FALSE;
430
431 }
432
433
434 static gboolean testapp_test_validate_account ()
435 {
436         int result_from_scanf = 0;
437         int account_id;
438         email_account_t *account=NULL;
439         int err_code = EMAIL_ERROR_NONE;
440         int handle = 0;
441         
442         testapp_print("\n>> Enter Account No: ");
443         result_from_scanf = scanf("%d",&account_id);
444
445 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
446         if( (err_code = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0 ) {
447                 testapp_print ("email_get_account failed \n");
448                 return FALSE;
449         }
450         else
451                 testapp_print ("email_get_account result account_name - %s \n", account->account_name);
452
453         if((err_code = email_validate_account(account_id, &handle)) == EMAIL_ERROR_NONE )
454                 testapp_print ("email_validate_account successful  handle : %u\n",handle);
455         else
456                 testapp_print ("email_validate_account failed err_code: %d \n",err_code);
457                 
458         return FALSE;
459
460 }
461
462
463 static gboolean testapp_test_cancel_validate_account ()
464 {
465         int result_from_scanf = 0;
466         int account_id = 0;
467         int err_code = EMAIL_ERROR_NONE;
468         unsigned account_handle = 0;
469
470         testapp_print("\n > Enter account_id: ");
471         result_from_scanf = scanf("%d", &account_id);
472
473         testapp_print("\n > Enter handle: ");
474         result_from_scanf = scanf("%d", &account_handle);
475
476         err_code = email_cancel_job(account_id, account_handle, EMAIL_CANCELED_BY_USER);
477         if(err_code == 0)
478                 testapp_print("email_cancel_job Success..!handle:[%d]", account_handle);
479         else
480                 testapp_print ("email_cancel_job failed err_code: %d \n",err_code);
481         
482         return FALSE;
483 }
484
485 static gboolean testapp_test_get_account()
486 {
487         int result_from_scanf = 0;
488         int account_id;
489         email_account_t *account=NULL;
490         int err_code = EMAIL_ERROR_NONE;
491         testapp_print("\n>> Enter Account No: ");
492         result_from_scanf = scanf("%d",&account_id);
493
494         typedef struct {
495                 int is_preset_account;
496                 int index_color;
497         } user_data_t;
498
499         testapp_print ("\n----------------------------------------------------------\n");
500         testapp_print ("email_get_account GET_FULL_DATA \n");
501         if( (err_code = email_get_account(account_id,GET_FULL_DATA,&account)) < 0) {
502                 testapp_print ("email_get_account failed - %d\n", err_code);
503                 return FALSE;
504         }
505
506         user_data_t* val = (user_data_t*) account->user_data;
507         int is_preset_account =  val? val->is_preset_account : 0;
508         int index_color = val? val->index_color : 0;
509
510         testapp_print ("email_get_account result\n"
511                         "account_name - %s \n"
512                         "user_email_address - %s \n"
513                         "incoming_server_secure_connection %d \n"
514                         "add_sig : %d \n"
515                         "signature %s \n"
516                         "add_my_address_to_bcc %d \n"
517                         "account_svc_id %d\n"
518                         "incoming_server_address %s\n"
519                         "outgoing_server_address %s\n"
520                         "default_mail_slot_size %d\n"
521                         "sync_status %d\n"
522                         "sync_disabled %d\n"
523                         "is_preset %d\n"
524                         "index_color %d\n"
525                         "certificate_path %s\n"
526                         "digest_type %d\n"
527                 ,
528                 account->account_name,
529                 account->user_email_address,
530                 account->incoming_server_secure_connection,
531                 account->options.add_signature,
532                 account->options.signature,
533                 account->options.add_my_address_to_bcc,
534                 account->account_svc_id,
535                 account->incoming_server_address,
536                 account->outgoing_server_address,
537                 account->default_mail_slot_size,
538                 account->sync_status,
539                 account->sync_disabled,
540                 is_preset_account,
541                 index_color,
542                 account->certificate_path,
543                 account->digest_type
544                 );
545
546         err_code = email_free_account(&account, 1);
547
548         testapp_print ("\n----------------------------------------------------------\n");
549         testapp_print ("email_get_account WITHOUT_OPTION \n");
550
551         if( (err_code = email_get_account(account_id, WITHOUT_OPTION, &account)) < 0) {
552                 testapp_print ("email_get_account failed \n");
553                 return FALSE;
554         }
555
556         testapp_print ("email_get_account result\n"
557                         "account_name - %s \n"
558                         "user_email_address - %s \n"
559                         "incoming_server_secure_connection %d \n"
560                         "add_signature : %d \n",
561                 account->account_name,
562                 account->user_email_address,
563                 account->incoming_server_secure_connection,
564                 account->options.add_signature
565         );
566
567         if(account->options.signature)
568                 testapp_print ("signature : %s\n", account->options.signature);
569         else
570                 testapp_print ("signature not retrieved \n");
571
572         err_code = email_free_account(&account, 1);
573
574         testapp_print ("\n----------------------------------------------------------\n");
575         testapp_print ("email_get_account ONLY_OPTION \n");
576
577         if( (err_code = email_get_account(account_id, ONLY_OPTION, &account)) < 0) {
578                 testapp_print ("email_get_account failed \n");
579                 return FALSE;
580         }
581
582         testapp_print ("email_get_account result\n"
583                         "add_sig : %d \n"
584                         "signature %s \n"
585                         "add_my_address_to_bcc %d\n"
586                         "account_svc_id %d\n",
587                 account->options.add_signature,
588                 account->options.signature,
589                 account->options.add_my_address_to_bcc,
590                 account->account_svc_id
591                 );
592
593         if(account->account_name)
594                 testapp_print ("account_name : %s \n", account->account_name);
595         else
596                 testapp_print ("account_name not retrieved \n");        
597
598         if(account->user_email_address)
599                 testapp_print ("user_email_address : %s \n", account->user_email_address);
600         else
601                 testapp_print ("user_email_address not retrieved \n");  
602         err_code = email_free_account(&account, 1);
603                 
604         return FALSE;
605 }
606
607 static gboolean testapp_test_get_account_list ()
608 {
609
610         int count, i;
611         email_account_t *account_list=NULL;
612         struct timeval tv_1, tv_2;
613         int interval;
614         int err_code = EMAIL_ERROR_NONE;
615
616         gettimeofday(&tv_1, NULL);
617
618         if((err_code = email_get_account_list(&account_list, &count)) < 0 ) {
619                 testapp_print("   email_get_account_list error\n");
620                 return false ;
621         }
622
623         gettimeofday(&tv_2, NULL);
624         interval = tv_2.tv_usec - tv_1.tv_usec;
625         testapp_print("\t testapp_test_get_account_list Proceed time %d us\n",interval);
626         
627         for(i=0;i<count;i++){
628                 testapp_print("   %2d) %-15s %-30s\n",account_list[i].account_id, 
629                         account_list[i].account_name, 
630                         account_list[i].user_email_address);
631         }
632
633         err_code = email_free_account(&account_list, count);
634         return FALSE;
635 }
636
637 static gboolean testapp_test_backup_account()
638 {
639         char *file_name = "accounts_file";
640         int error_code;
641         error_code = email_backup_accounts_into_secure_storage(file_name);
642         testapp_print("\n email_backup_accounts_into_secure_storage returned [%d]\n",error_code);
643         return FALSE;
644 }
645 static gboolean testapp_test_restore_account()
646 {
647         char *file_name = "accounts_file";
648         int error_code;
649         error_code = email_restore_accounts_from_secure_storage(file_name);
650         testapp_print("\n email_restore_accounts_from_secure_storage returned [%d]\n",error_code);
651         return FALSE;
652 }
653
654 static gboolean testapp_test_get_password_length_of_account()
655 {
656         int result_from_scanf = 0;
657         int error_code, password_length, account_id;
658
659         testapp_print("\n input account id\n");
660         result_from_scanf = scanf("%d", &account_id);
661         error_code = email_get_password_length_of_account(account_id, &password_length);
662         testapp_print("testapp_test_get_password_length_of_account returned [%d]\n",password_length);
663         return FALSE;
664 }
665
666 static gboolean testapp_test_query_server_info()
667 {
668         int result_from_scanf = 0;
669         int error_code;
670         char domain_name[255];
671         email_server_info_t *result_server_info;
672
673         testapp_print("\n input domain name\n");
674         result_from_scanf = scanf("%s", domain_name);
675
676         error_code = email_query_server_info(domain_name, &result_server_info);
677         testapp_print("email_query_server_info returned [%d]\n",error_code);
678         if(error_code == EMAIL_ERROR_NONE)
679                 testapp_print("service_name [%s]\n", result_server_info->service_name);
680         return FALSE;
681 }
682
683 static gboolean testapp_test_clear_all_notification()
684 {
685         int error_code;
686
687         error_code = email_clear_all_notification_bar();
688         testapp_print("email_clear_all_notification_bar returned [%d]\n",error_code);
689         return FALSE;
690 }
691
692 static gboolean testapp_test_save_default_account_id()
693 {
694         int result_from_scanf = 0;
695         int error_code;
696         int account_id = 0;
697
698         testapp_print ("\nInput default account id : ");
699
700         result_from_scanf = scanf("%d", &account_id);
701
702         error_code = email_save_default_account_id(account_id);
703
704         testapp_print("email_save_default_account_id returned [%d]\n",error_code);
705         return FALSE;
706 }
707
708 static gboolean testapp_test_load_default_account_id()
709 {
710         int error_code;
711         int account_id = 0;
712
713         error_code = email_load_default_account_id(&account_id);
714
715         testapp_print ("\ndefault account id : %d\n", account_id);
716         testapp_print("email_load_default_account_id returned [%d]\n",error_code);
717         return FALSE;
718 }
719
720 static gboolean testapp_test_add_certificate()
721 {
722         int result_from_scanf = 0;
723         int ret = 0;
724         char save_name[50] = {0, };
725         char certificate_path[255] = {0, };
726
727         testapp_print("Input cert path : ");
728         result_from_scanf = scanf("%s", certificate_path);      
729
730         testapp_print("Input cert email-address : ");
731         result_from_scanf = scanf("%s", save_name);
732
733         testapp_print("cert path : [%s]", certificate_path);
734         testapp_print("email-address : [%s]", save_name);
735
736         ret = email_add_certificate(certificate_path, save_name);
737         if (ret != EMAIL_ERROR_NONE) {
738                 testapp_print("Add certificate failed\n");
739                 return false;
740         }
741
742         testapp_print("Add certificate success\n");
743         return true;
744 }
745
746 static gboolean testapp_test_get_certificate()
747 {
748         int result_from_scanf = 0;
749         int ret = 0;
750         char save_name[20] = {0, };
751         email_certificate_t *certificate = NULL;
752
753         testapp_print("Input cert email-address : ");
754         result_from_scanf = scanf("%s", save_name);
755
756         ret = email_get_certificate(save_name, &certificate);
757         if (ret != EMAIL_ERROR_NONE) {
758                 testapp_print("Get certificate failed\n");
759                 return false;
760         }
761
762         testapp_print("certificate_id : %d\n", certificate->certificate_id);
763         testapp_print("issue_year : %d\n", certificate->issue_year);
764         testapp_print("issue_month : %d\n", certificate->issue_month);
765         testapp_print("issue_day : %d\n", certificate->issue_day);
766         testapp_print("expiration_year : %d\n", certificate->expiration_year);
767         testapp_print("expiration_month : %d\n", certificate->expiration_month);
768         testapp_print("expiration_day : %d\n", certificate->expiration_day);
769         testapp_print("issue_organization_name : %s\n", certificate->issue_organization_name);
770         testapp_print("subject_string : %s\n", certificate->subject_str);
771         testapp_print("file path : %s\n", certificate->filepath);
772
773         if (certificate)
774                 email_free_certificate(&certificate, 1);
775
776         testapp_print("Get certificate success\n");
777         return true;
778 }
779
780 static gboolean testapp_test_delete_certificate()
781 {
782         int result_from_scanf = 0;
783         int ret = 0;
784         char save_name[20] = {0, };
785
786         testapp_print("Input cert email-address : ");
787         result_from_scanf = scanf("%s", save_name);
788
789         ret = email_delete_certificate(save_name);
790         if (ret != EMAIL_ERROR_NONE) {
791                 testapp_print("Delete certificate failed\n");
792                 return false;
793         }
794
795         testapp_print("Delete certificate success\n");
796         return true;
797 }
798 static gboolean testapp_test_interpret_command (int selected_number)
799 {
800         gboolean go_to_loop = TRUE;
801         
802         switch (selected_number) {
803                 case 1:
804                         testapp_test_create_account();
805                         break;
806
807                 case 2:
808                         testapp_test_update_account();
809                         break;
810
811                 case 3:
812                         testapp_test_delete_account();
813                         break;
814
815                 case 4:
816                         testapp_test_get_account();
817                         break;
818                 
819                 case 5:
820                         testapp_test_get_account_list();
821                         break;
822
823                 case 7:
824                         testapp_test_validate_account();
825                         break;          
826
827                 case 8:
828                         testapp_test_cancel_validate_account();
829                         break;  
830
831                 case 9:
832                         testapp_test_backup_account();
833                         break;  
834
835                 case 10:
836                         testapp_test_restore_account();
837                         break;  
838
839                 case 11:
840                         testapp_test_get_password_length_of_account();
841                         break;
842
843                 case 12:
844                         testapp_test_query_server_info();
845                         break;
846
847                 case 13:
848                         testapp_test_clear_all_notification();
849                         break;
850
851                 case 14:
852                         testapp_test_save_default_account_id();
853                         break;
854
855                 case 15:
856                         testapp_test_load_default_account_id();
857                         break;
858
859                 case 16:
860                         testapp_test_add_certificate();
861                         break;
862
863                 case 17:
864                         testapp_test_get_certificate();
865                         break;
866
867                 case 18:
868                         testapp_test_delete_certificate();
869                         break;
870
871                 case 0:
872                         go_to_loop = FALSE;
873                         break;
874
875                 default:
876                         break;
877         }
878
879         return go_to_loop;
880 }
881
882 void testapp_account_main ()
883 {
884         gboolean go_to_loop = TRUE;
885         int menu_number = 0;
886         int result_from_scanf = 0;
887         
888         while (go_to_loop) {
889                 testapp_show_menu (EMAIL_ACCOUNT_MENU);
890                 testapp_show_prompt (EMAIL_ACCOUNT_MENU);
891                         
892                 result_from_scanf = scanf ("%d", &menu_number);
893
894                 go_to_loop = testapp_test_interpret_command (menu_number);
895         }       
896 }
897