5eae24106133a0cf67ebde2956d296fa15efd8fe
[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-smime.h"
32 #include "email-api-account.h"
33 #include "email-api-network.h"
34
35 /* internal header */
36 #include "testapp-utility.h"
37 #include "testapp-account.h"
38 #include <sys/time.h>
39 #include <sys/times.h>
40
41 /* internal defines */
42
43 #define GWB_RECV_SERVER_ADDR        "pop.gawab.com"
44 #define GWB_SMTP_SERVER_ADDR        "smtp.gawab.com"
45
46 #define VDF_RECV_SERVER_ADDR  "imap.email.vodafone.de"
47 #define VDF_SMTP_SERVER_ADDR  "smtp.email.vodafone.de"
48
49 /*  SAMSUNG 3G TEST */
50 #define S3G_RECV_SERVER_ADDR                "165.213.73.235"
51 #define S3G_RECV_SERVER_PORT                EMAIL_POP3_PORT
52 #define S3G_RECV_USE_SECURITY               0
53 #define S3G_RECV_IMAP_USE_SECURITY      1
54 #define S3G_SMTP_SERVER_ADDR                "165.213.73.235"
55 #define S3G_SMTP_SERVER_PORT                465
56 #define S3G_SMTP_AUTH                                   1
57 #define S3G_SMTP_USE_SECURITY         1
58 #define S3G_KEEP_ON_SERVER                    1
59
60 gboolean  testapp_create_account_object(email_account_t **result_account)
61 {
62         email_account_t *account = NULL;
63         char id_string[100] = { 0, }, password_string[1000] = { 0, }, address_string[100]  = { 0, };
64         char accesss_token[1000] = { 0, }, refresh_token[1000] = { 0, };
65         int samsung3g_account_index;
66         int account_type;
67
68         testapp_print("1. Gawab\n");
69         testapp_print("2. Vodafone\n");
70         testapp_print("4. SAMSUNG 3G TEST (POP)\n");
71         testapp_print("5. SAMSUNG 3G TEST (IMAP)\n");
72         testapp_print("6. Gmail (POP3)\n");
73         testapp_print("7. Gmail (IMAP4)\n");
74         testapp_print("8. Active Sync (dummy)\n");
75         testapp_print("9. AOL\n");
76         testapp_print("10. Hotmail\n");
77         testapp_print("11. Daum (IMAP4)\n");
78         testapp_print("12. Daum (POP3)\n");
79         testapp_print("13. Yahoo (IMAP ID)\n");
80         testapp_print("14. Gmail IMAP with XOAUTH\n");
81         testapp_print("15. Yandex\n");
82         testapp_print("16. mopera\n");
83         testapp_print("Choose server type: ");
84
85
86         if (0 >= scanf("%d",&account_type))
87                 testapp_print("Invalid input. ");
88
89         switch(account_type) {
90                 case 4 : 
91                 case 5 :
92                         do {
93                                 testapp_print("Enter your account index [1~10] : ");
94                                 if (0 >= scanf("%d",&samsung3g_account_index))
95                                         testapp_print("Invalid input. ");
96                         }while( samsung3g_account_index > 10 || samsung3g_account_index < 1);
97                         sprintf(id_string, "test%02d", samsung3g_account_index);
98                         sprintf(address_string, "test%02d@streaming.s3glab.net", samsung3g_account_index);
99                         sprintf(password_string, "test%02d", samsung3g_account_index);
100                         break;
101                 case 14 :
102                         testapp_print("Enter email address : ");
103                         if (0 >= scanf("%s", address_string))
104                                 testapp_print("Invalid input. ");
105                         strcpy(id_string, address_string);
106
107                         testapp_print("Enter access token : ");
108                         if (0 >= scanf("%s", accesss_token))
109                                 testapp_print("Invalid input. ");
110
111                         testapp_print("Enter refresh token : ");
112                         if (0 >= scanf("%s", refresh_token))
113                                 testapp_print("Invalid input. ");
114
115                         snprintf(password_string, 100, "%s\001%s\001", accesss_token, refresh_token);
116                         break;
117                 default:
118                         testapp_print("Enter email address : ");
119                         if (0 >= scanf("%s", address_string))
120                                 testapp_print("Invalid input. ");
121
122                         testapp_print("Enter id : ");
123                         if (0 >= scanf("%s", id_string))
124                                 testapp_print("Invalid input. ");
125
126                         testapp_print("Enter password_string : ");
127                         if (0 >= scanf("%s", password_string))
128                                 testapp_print("Invalid input. ");
129                         break;
130         }
131
132         account = malloc(sizeof(email_account_t));
133         memset(account, 0x00, sizeof(email_account_t));
134
135         typedef struct {
136                 int is_preset_account;
137                 int index_color;
138         } user_data_t;
139         user_data_t data = (user_data_t) {1, 0};
140         /* if user_data_t has any pointer member, please don't use sizeof(). */
141         /* You need to serialize user_data to buffer and then take its length */
142         int data_length = sizeof(data);
143
144         /* Common Options */
145         account->retrieval_mode                          = EMAIL_IMAP4_RETRIEVAL_MODE_ALL;
146         account->incoming_server_secure_connection           = 1;
147         account->outgoing_server_type                    = EMAIL_SERVER_TYPE_SMTP;
148         account->auto_download_size                                  = 2;
149         account->outgoing_server_use_same_authenticator  = 1;
150         account->auto_resend_times                       = 3;
151         account->pop_before_smtp                         = 0;
152         account->incoming_server_requires_apop           = 0;
153         account->incoming_server_authentication_method   = 0;
154         account->logo_icon_path                          = NULL;
155         account->color_label                             = (128 << 16) | (128 << 8) | (128);
156         account->user_data                               = malloc (data_length);
157         memcpy( account->user_data, (void*) &data, data_length );
158         account->user_data_length                        = data_length;
159         account->options.priority                        = 3;
160         account->options.keep_local_copy                 = 1;
161         account->options.req_delivery_receipt            = 0;
162         account->options.req_read_receipt                = 0;
163         account->options.download_limit                  = 0;
164         account->options.block_address                   = 0;
165         account->options.block_subject                   = 0;
166         account->options.display_name_from               = NULL;
167         account->options.reply_with_body                 = 0;
168         account->options.forward_with_files              = 0;
169         account->options.add_myname_card                 = 0;
170         account->options.add_signature                   = 0;
171         account->options.signature                       = NULL;
172         account->options.add_my_address_to_bcc           = 0;
173         account->check_interval                          = 0;
174         account->keep_mails_on_pop_server_after_download = 1;
175         account->default_mail_slot_size                  = 20;
176         account->roaming_option                          = EMAIL_ROAMING_OPTION_RESTRICTED_BACKGROUND_TASK;
177         account->peak_interval                           = 30;
178         account->peak_days                               = EMAIL_PEAK_DAYS_MONDAY | EMAIL_PEAK_DAYS_TUEDAY | EMAIL_PEAK_DAYS_THUDAY | EMAIL_PEAK_DAYS_FRIDAY;
179         account->peak_start_time                         = 830;
180         account->peak_end_time                           = 1920;
181
182         account->account_name                            = strdup(address_string);
183         account->user_display_name                       = strdup(id_string);
184         account->user_email_address                      = strdup(address_string);
185         account->reply_to_address                        = strdup(address_string);
186         account->return_address                          = strdup(address_string);
187
188         account->incoming_server_user_name               = strdup(id_string);
189         account->incoming_server_password                = strdup(password_string);
190         account->outgoing_server_user_name               = strdup(id_string);
191         account->outgoing_server_password                    = strdup(password_string);
192
193         switch (account_type) {
194                 case 1:/*  gawab */
195                         account->incoming_server_type                    = EMAIL_SERVER_TYPE_POP3 ;
196                         account->incoming_server_address                 = strdup(GWB_RECV_SERVER_ADDR);
197                         account->incoming_server_port_number         = EMAIL_POP3S_PORT;
198                         account->outgoing_server_address             = strdup(GWB_SMTP_SERVER_ADDR);
199                         account->incoming_server_secure_connection       = 1;
200                         account->outgoing_server_need_authentication = 1;
201                         account->outgoing_server_port_number         = EMAIL_SMTPS_PORT;
202                         account->outgoing_server_secure_connection   = 1;
203
204                         break;
205
206                 case 2:/*  vadofone */
207                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
208                         account->incoming_server_address= strdup(VDF_RECV_SERVER_ADDR);
209                         account->incoming_server_port_number = EMAIL_IMAP_PORT;
210                         account->outgoing_server_address     = strdup(VDF_SMTP_SERVER_ADDR);
211                         account->incoming_server_secure_connection      = 0;
212                         account->outgoing_server_need_authentication = 0;
213                         break;
214
215                 case 4:/*  SAMSUNG 3G TEST */
216                         account->incoming_server_type            = EMAIL_SERVER_TYPE_POP3;
217                         account->incoming_server_address         = strdup(S3G_RECV_SERVER_ADDR);
218                         account->incoming_server_port_number = S3G_RECV_SERVER_PORT;
219                         account->outgoing_server_address     = strdup(S3G_SMTP_SERVER_ADDR);
220                         account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT;
221                         account->incoming_server_secure_connection      = S3G_RECV_USE_SECURITY;
222                         account->outgoing_server_secure_connection  = S3G_SMTP_USE_SECURITY;
223                         account->outgoing_server_need_authentication = S3G_SMTP_AUTH;
224                         break;
225
226                 case 5:/*  SAMSUNG 3G TEST */
227                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
228                         account->incoming_server_address= strdup(S3G_RECV_SERVER_ADDR);
229                         account->incoming_server_port_number = EMAIL_IMAPS_PORT;
230                         account->outgoing_server_address     = strdup(S3G_SMTP_SERVER_ADDR);
231                         account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT;
232                         account->incoming_server_secure_connection      = 1;
233                         account->outgoing_server_secure_connection  = S3G_SMTP_USE_SECURITY;
234                         account->outgoing_server_need_authentication = S3G_SMTP_AUTH;
235                         break;
236
237                 case 6:/*  Gmail POP3 */
238                         account->incoming_server_type  = EMAIL_SERVER_TYPE_POP3;
239                         account->incoming_server_address= strdup("pop.gmail.com");
240                         account->incoming_server_port_number = 995;
241                         account->incoming_server_secure_connection      = 1;
242                         account->outgoing_server_address    = strdup("smtp.gmail.com");
243                         account->outgoing_server_port_number = 465;
244                         account->outgoing_server_secure_connection = 1;
245                         account->outgoing_server_need_authentication = 1;
246                         break;
247
248                 case 7 : /*  Gmail IMAP4 */
249                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
250                         account->incoming_server_address = strdup("imap.gmail.com");
251                         account->incoming_server_port_number = 993;
252                         account->incoming_server_secure_connection      = 1;
253                         account->outgoing_server_address = strdup("smtp.gmail.com");
254                         account->outgoing_server_port_number = 465;
255                         account->outgoing_server_secure_connection = 1;
256                         account->outgoing_server_need_authentication   = EMAIL_AUTHENTICATION_METHOD_DEFAULT;
257                         account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_NO_AUTH;
258                         break;
259
260                 case 8: /*  Active Sync */
261                         account->incoming_server_type  = EMAIL_SERVER_TYPE_ACTIVE_SYNC;
262                         account->incoming_server_address= strdup("");
263                         account->incoming_server_port_number = 0;
264                         account->incoming_server_secure_connection      = 1;
265                         account->outgoing_server_address    = strdup("");
266                         account->outgoing_server_port_number = 0;
267                         account->outgoing_server_secure_connection = 1;
268                         account->outgoing_server_need_authentication = 1;
269                         break;
270
271                 case 9: /*  AOL */
272                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
273                         account->incoming_server_address= strdup("imap.aol.com");
274                         account->incoming_server_port_number = 143;
275                         account->incoming_server_secure_connection      = 0;
276                         account->outgoing_server_address    = strdup("smtp.aol.com");
277                         account->outgoing_server_port_number = 587;
278                         account->outgoing_server_secure_connection = 0;
279                         account->outgoing_server_need_authentication = 1;
280                         break;
281
282                 case 10: /*  Hotmail */
283                         account->incoming_server_type  = EMAIL_SERVER_TYPE_POP3;
284                         account->incoming_server_address= strdup("pop3.live.com");
285                         account->incoming_server_port_number = 995;
286                         account->incoming_server_secure_connection      = 1;
287                         account->outgoing_server_address    = strdup("smtp.live.com");
288                         account->outgoing_server_port_number = 587;
289                         account->outgoing_server_secure_connection  = 0x02;
290                         account->outgoing_server_need_authentication = 1;
291                         break;
292
293                 case 11:/*  Daum IMAP4*/
294                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
295                         account->incoming_server_address= strdup("imap.daum.net");
296                         account->incoming_server_port_number = 993;
297                         account->incoming_server_secure_connection      = 1;
298                         account->outgoing_server_address    = strdup("smtp.daum.net");
299                         account->outgoing_server_port_number = 465;
300                         account->outgoing_server_secure_connection = 1;
301                         account->outgoing_server_need_authentication = 1;
302                         break;
303
304                 case 12:/*  Daum POP3*/
305                         account->incoming_server_type  = EMAIL_SERVER_TYPE_POP3;
306                         account->incoming_server_address= strdup("pop.daum.net");
307                         account->incoming_server_port_number = 995;
308                         account->incoming_server_secure_connection      = 1;
309                         account->outgoing_server_address    = strdup("smtp.daum.net");
310                         account->outgoing_server_port_number = 465;
311                         account->outgoing_server_secure_connection = 1;
312                         account->outgoing_server_need_authentication = 1;
313                         break;
314
315                 case 13: /* Yahoo IMAP ID */
316                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
317                         account->incoming_server_address= strdup("samsung.imap.mail.yahoo.com");
318                         account->incoming_server_port_number = 993;
319                         account->incoming_server_secure_connection      = 1;
320                         account->outgoing_server_address    = strdup("samsung.smtp.mail.yahoo.com");
321                         account->outgoing_server_port_number = 465;
322                         account->outgoing_server_secure_connection = 1;
323                         account->outgoing_server_need_authentication = 1;
324                         break;
325
326                 case 14 : /*  XOAUTH */
327                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
328                         account->incoming_server_address = strdup("imap.gmail.com");
329                         account->incoming_server_port_number = 993;
330                         account->incoming_server_secure_connection      = 1;
331                         account->outgoing_server_address = strdup("smtp.gmail.com");
332                         account->outgoing_server_port_number = 465;
333                         account->outgoing_server_secure_connection = 1;
334                         account->outgoing_server_need_authentication   = EMAIL_AUTHENTICATION_METHOD_XOAUTH2;
335                         account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_XOAUTH2;
336                         break;
337
338                 case 15 : /*  yandex */
339                         account->incoming_server_type  = EMAIL_SERVER_TYPE_IMAP4;
340                         account->incoming_server_address = strdup("imap.yandex.ru");
341                         account->incoming_server_port_number = 993;
342                         account->incoming_server_secure_connection      = 1;
343                         account->outgoing_server_address = strdup("smtp.yandex.ru");
344                         account->outgoing_server_port_number = 465;
345                         account->outgoing_server_secure_connection = 1;
346                         account->outgoing_server_need_authentication   = EMAIL_AUTHENTICATION_METHOD_DEFAULT;
347                         account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_DEFAULT;
348                         break;
349
350                 case 16 : /*  mopera */
351                         account->incoming_server_type                  = EMAIL_SERVER_TYPE_POP3;
352                         account->incoming_server_address               = strdup("mail.mopera.net");
353                         account->incoming_server_port_number           = 110;
354                         account->incoming_server_secure_connection         = 0;
355                         account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_NO_AUTH;
356                         account->outgoing_server_address               = strdup("mail.mopera.net");
357                         account->outgoing_server_port_number           = 465;
358                         account->outgoing_server_secure_connection     = 0;
359                         account->outgoing_server_need_authentication   = EMAIL_AUTHENTICATION_METHOD_DEFAULT;
360                         break;
361
362                 default:
363                         testapp_print("Invalid Account Number\n");
364                         return FALSE;
365                         break;
366         }
367         account->account_svc_id = 77;
368
369         if(result_account)
370                 *result_account = account;
371
372         return TRUE;
373 }
374
375 static gboolean testapp_test_add_account_with_validation()
376 {
377         int err = EMAIL_ERROR_NONE;
378         email_account_t *account = NULL;
379         int handle;
380
381         if(!testapp_create_account_object(&account)) {
382                 testapp_print ("testapp_test_create_account_by_account_type error\n");
383                 return FALSE;
384         }
385
386         err = email_add_account_with_validation(account, &handle);
387         if( err < 0) {
388                 testapp_print ("email_add_account_with_validation error : %d\n", err);
389                 err = email_free_account(&account, 1);
390                 return FALSE;
391         }
392
393         testapp_print ("email_add_account succeed. account_id\n", account->account_id);
394
395         err = email_free_account(&account, 1);
396
397         return TRUE;
398 }
399
400 static gboolean testapp_test_update_account()
401 {
402         int account_id;
403         email_account_t *account = NULL;
404         //char account_name[256];
405         int err = EMAIL_ERROR_NONE;
406         //char signature[100] = {0};
407         //char user_email_address[256] = {0,};
408         //int add_my_address_to_bcc = 0;
409         int with_validation = 0; //account_svc_id = 0, 
410         
411         testapp_print("\n>> Enter Account ID: ");
412         if (0 >= scanf("%d",&account_id))
413                 testapp_print("Invalid input. ");
414
415         if( (err = email_get_account(account_id, GET_FULL_DATA,&account)) != EMAIL_ERROR_NONE) {
416                 testapp_print ("email_get_account failed - %d\n", err);
417                 return false;
418         }
419
420         testapp_print ("email_get_account result account_name - %s \n", account->account_name);
421         testapp_print ("email_get_account result address - %s \n", account->user_email_address);
422         testapp_print ("email_get_account result signature - %s \n", account->options.signature);
423         testapp_print ("email_get_account result check_interval - %d \n", account->check_interval);
424         
425         testapp_print("\n Enter new check interval (in mins):");
426         if (0 >= scanf("%d",&(account->check_interval)))
427                 testapp_print("Invalid input. ");
428 /*
429         testapp_print("\n Enter new peak interval (in mins):");
430         if (0 >= scanf("%d",&(account->peak_interval));
431
432         testapp_print("\n Enter new peak days:");
433         if (0 >= scanf("%d",&(account->peak_days));
434
435         testapp_print("\n Enter new peak start time:");
436         if (0 >= scanf("%d",&(account->peak_start_time));
437
438         testapp_print("\n Enter new peak end time:");
439         if (0 >= scanf("%d",&(account->peak_end_time));
440 */
441
442 /*
443         testapp_print("\n Enter new Account name:");
444         if (0 >= scanf("%s",account_name);
445
446         testapp_print("\n Enter new email addr:");
447         if (0 >= scanf("%s",user_email_address);
448
449         testapp_print("\n Enter new signature:");
450         if (0 >= scanf("%s",signature);
451
452         testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) ");
453         if (0 >= scanf("%d",&add_my_address_to_bcc);
454
455         testapp_print("\n>> Enter account_svc_id: ");
456         if (0 >= scanf("%d",&account_svc_id);
457
458         testapp_print("\n>> With validation ? (0: No, 1:Yes) ");
459         if (0 >= scanf("%d",&with_validation);
460 */
461     if( account )  {
462                 testapp_print("\n Assigning New Account name: (%s)", account->account_name);
463                 testapp_print("\n Assigning New Signature: (%s)\n", account->options.signature);
464                 /*
465                 account->account_name = strdup(account_name);
466                 account->user_email_address = strdup(user_email_address);
467                 account->options.signature = strdup(signature);
468                 account->options.add_my_address_to_bcc = add_my_address_to_bcc;
469                 account->account_svc_id = account_svc_id;
470                 */
471
472                 if(with_validation) {
473                         if((err = email_update_account_with_validation(account_id, account)) != EMAIL_ERROR_NONE){
474                                 testapp_print ("email_update_account_with_validation failed - %d\n", err);
475                                 return false;
476                         }
477                                 testapp_print ("email_update_account_with_validation successful \n");
478                 }
479                 else {
480                         if((err = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) {
481                                 testapp_print ("email_update_account failed - %d\n", err);
482                                 return false;
483                         }
484                         testapp_print ("email_update_account successful \n");
485                 }
486     }
487         return true;
488 }
489
490 static gboolean testapp_test_delete_account ()
491 {
492         int account_id;
493         email_account_t *account=NULL;
494         int err = EMAIL_ERROR_NONE;
495
496         testapp_print("\n>> Enter Account No: ");
497         if (0 >= scanf("%d",&account_id))
498                 testapp_print("Invalid input. ");
499
500 /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */
501         if( (err = email_get_account(account_id, WITHOUT_OPTION,&account)) < 0) {
502                 testapp_print ("email_get_account failed \n");
503                 testapp_print("testapp_test_delete_account failed\n");
504         }
505         else {
506                 testapp_print ("email_get_account result account_name - %s \n", account->account_name);
507
508                 if((err = email_delete_account(account_id)) < 0) 
509                         testapp_print ("email_delete_account failed[%d]\n", err);
510                 else
511                         testapp_print ("email_delete_account successful \n");
512         }
513         return FALSE;
514
515 }
516
517
518 static gboolean testapp_test_validate_account ()
519 {
520         email_account_t *account = NULL;
521         int err_code = EMAIL_ERROR_NONE;
522         int handle = 0;
523         
524         if(!testapp_create_account_object(&account)) {
525                 testapp_print ("testapp_create_account_object error\n");
526                 return FALSE;
527         }
528
529         if((err_code = email_validate_account_ex(account, &handle)) == EMAIL_ERROR_NONE )
530                 testapp_print ("email_validate_account_ex successful handle : %u\n",handle);
531         else
532                 testapp_print ("email_validate_account_ex failed err_code : %d \n",err_code);
533
534         if(account)
535                 email_free_account(&account, 1);
536                 
537         return FALSE;
538
539 }
540
541
542 static gboolean testapp_test_cancel_validate_account ()
543 {
544         int account_id = 0;
545         int err_code = EMAIL_ERROR_NONE;
546         unsigned account_handle = 0;
547
548         testapp_print("\n > Enter account_id: ");
549         if (0 >= scanf("%d", &account_id))
550                 testapp_print("Invalid input. ");
551
552         testapp_print("\n > Enter handle: ");
553         if (0 >= scanf("%d", &account_handle))
554                 testapp_print("Invalid input. ");
555
556         err_code = email_cancel_job(account_id, account_handle, EMAIL_CANCELED_BY_USER);
557         if(err_code == 0)
558                 testapp_print("email_cancel_job Success..!handle:[%d]", account_handle);
559         else
560                 testapp_print ("email_cancel_job failed err_code: %d \n",err_code);
561         
562         return FALSE;
563 }
564
565 static gboolean testapp_test_get_account()
566 {
567         int account_id;
568         email_account_t *account=NULL;
569         int err_code = EMAIL_ERROR_NONE;
570         testapp_print("\n>> Enter Account No: ");
571         if (0 >= scanf("%d",&account_id))
572                 testapp_print("Invalid input. ");
573
574         typedef struct {
575                 int is_preset_account;
576                 int index_color;
577         } user_data_t;
578
579         testapp_print ("\n----------------------------------------------------------\n");
580         testapp_print ("email_get_account GET_FULL_DATA \n");
581         if( (err_code = email_get_account(account_id,GET_FULL_DATA,&account)) < 0) {
582                 testapp_print ("email_get_account failed - %d\n", err_code);
583                 return FALSE;
584         }
585
586         user_data_t* val = (user_data_t*) account->user_data;
587         int is_preset_account =  val? val->is_preset_account : 0;
588         int index_color = val? val->index_color : 0;
589
590         testapp_print ("email_get_account result\n"
591                         "account_name - %s \n"
592                         "user_email_address - %s \n"
593                         "incoming_server_secure_connection %d \n"
594                         "add_sig : %d \n"
595                         "signature %s \n"
596                         "add_my_address_to_bcc %d \n"
597                         "account_svc_id %d\n"
598                         "incoming_server_address %s\n"
599                         "outgoing_server_address %s\n"
600                         "default_mail_slot_size %d\n"
601                         "sync_status %d\n"
602                         "sync_disabled %d\n"
603                         "is_preset %d\n"
604                         "index_color %d\n"
605                         "certificate_path %s\n"
606                         "digest_type %d\n"
607                         "auto_resend_times %d\n"
608                         "roaming_option %d\n"
609                         "peak_interval %d\n"
610                         "peak_days %d\n"
611                         "peak_start_time %d\n"
612                         "peak_end_time %d\n"
613                         "color_label %d\n"
614                         "notification_status %d\n"
615                         "vibrate_status %d\n"
616                         "display_content_status %d\n"
617                         "default_ringtone_status %d\n"
618                         "alert_ringtone_path %s\n"
619                 ,
620                 account->account_name,
621                 account->user_email_address,
622                 account->incoming_server_secure_connection,
623                 account->options.add_signature,
624                 account->options.signature,
625                 account->options.add_my_address_to_bcc,
626                 account->account_svc_id,
627                 account->incoming_server_address,
628                 account->outgoing_server_address,
629                 account->default_mail_slot_size,
630                 account->sync_status,
631                 account->sync_disabled,
632                 is_preset_account,
633                 index_color,
634                 account->certificate_path,
635                 account->digest_type,
636                 account->auto_resend_times,
637                 account->roaming_option,
638                 account->peak_interval,
639                 account->peak_days,
640                 account->peak_start_time,
641                 account->peak_end_time,
642                 account->color_label,
643                 account->options.notification_status,
644                 account->options.vibrate_status,
645                 account->options.display_content_status,
646                 account->options.default_ringtone_status,
647                 account->options.alert_ringtone_path
648                 );
649
650         err_code = email_free_account(&account, 1);
651
652         testapp_print ("\n----------------------------------------------------------\n");
653         testapp_print ("email_get_account WITHOUT_OPTION \n");
654
655         if( (err_code = email_get_account(account_id, WITHOUT_OPTION, &account)) < 0) {
656                 testapp_print ("email_get_account failed \n");
657                 return FALSE;
658         }
659
660         testapp_print ("email_get_account result\n"
661                         "account_name - %s \n"
662                         "user_email_address - %s \n"
663                         "incoming_server_secure_connection %d \n"
664                         "add_signature : %d \n",
665                 account->account_name,
666                 account->user_email_address,
667                 account->incoming_server_secure_connection,
668                 account->options.add_signature
669         );
670
671         if(account->options.signature)
672                 testapp_print ("signature : %s\n", account->options.signature);
673         else
674                 testapp_print ("signature not retrieved \n");
675
676         err_code = email_free_account(&account, 1);
677
678         testapp_print ("\n----------------------------------------------------------\n");
679         testapp_print ("email_get_account ONLY_OPTION \n");
680
681         if( (err_code = email_get_account(account_id, ONLY_OPTION, &account)) < 0) {
682                 testapp_print ("email_get_account failed \n");
683                 return FALSE;
684         }
685
686         testapp_print ("email_get_account result\n"
687                         "add_sig : %d \n"
688                         "signature %s \n"
689                         "add_my_address_to_bcc %d\n"
690                         "account_svc_id %d\n",
691                 account->options.add_signature,
692                 account->options.signature,
693                 account->options.add_my_address_to_bcc,
694                 account->account_svc_id
695                 );
696
697         if(account->account_name)
698                 testapp_print ("account_name : %s \n", account->account_name);
699         else
700                 testapp_print ("account_name not retrieved \n");        
701
702         if(account->user_email_address)
703                 testapp_print ("user_email_address : %s \n", account->user_email_address);
704         else
705                 testapp_print ("user_email_address not retrieved \n");  
706         err_code = email_free_account(&account, 1);
707                 
708         return FALSE;
709 }
710
711 static gboolean testapp_test_get_account_list ()
712 {
713
714         int count, i;
715         email_account_t *account_list=NULL;
716         struct timeval tv_1, tv_2;
717         int interval;
718         int err_code = EMAIL_ERROR_NONE;
719
720         gettimeofday(&tv_1, NULL);
721
722         if((err_code = email_get_account_list(&account_list, &count)) < 0 ) {
723                 testapp_print("   email_get_account_list error\n");
724                 return false ;
725         }
726
727         gettimeofday(&tv_2, NULL);
728         interval = tv_2.tv_usec - tv_1.tv_usec;
729         testapp_print("\t testapp_test_get_account_list Proceed time %d us\n",interval);
730         
731         for(i=0;i<count;i++){
732                 testapp_print("   %2d) %-15s %-30s\n",account_list[i].account_id, 
733                         account_list[i].account_name, 
734                         account_list[i].user_email_address);
735         }
736
737         err_code = email_free_account(&account_list, count);
738         return FALSE;
739 }
740
741 static gboolean testapp_test_update_check_interval()
742 {
743         int account_id = 0;
744         int err_code = EMAIL_ERROR_NONE;
745         email_account_t *account = NULL;
746
747         testapp_print("\n Enter account id :");
748         if (0 >= scanf("%d",&account_id))
749                 testapp_print("Invalid input. ");
750
751         if( (err_code = email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account)) != EMAIL_ERROR_NONE) {
752                 testapp_print ("email_get_account failed [%d]\n", err_code);
753                 goto FINISH_OFF;
754         }
755
756         testapp_print("\n Enter new check interval (in mins):");
757         if (0 >= scanf("%d",&(account->check_interval)))
758                 testapp_print("Invalid input. ");
759
760         if((err_code = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) {
761                 testapp_print ("email_update_account failed [%d]\n", err_code);
762                 goto FINISH_OFF;
763         }
764
765         testapp_print ("email_update_account successful \n");
766
767 FINISH_OFF:
768         if(account)
769                 email_free_account(&account, 1);
770
771         return err_code;
772 }
773
774 static gboolean testapp_test_backup_account()
775 {
776         char *file_name = "/opt/usr/data/email/accounts_file";
777         int error_code;
778         error_code = email_backup_accounts_into_secure_storage(file_name);
779         testapp_print("\n email_backup_accounts_into_secure_storage returned [%d]\n",error_code);
780         return FALSE;
781 }
782 static gboolean testapp_test_restore_account()
783 {
784         char *file_name = "/opt/usr/data/email/accounts_file";
785         int error_code;
786         error_code = email_restore_accounts_from_secure_storage(file_name);
787         testapp_print("\n email_restore_accounts_from_secure_storage returned [%d]\n",error_code);
788         return FALSE;
789 }
790
791 static gboolean testapp_test_get_password_length_of_account()
792 {
793         int password_length, account_id;
794
795         testapp_print("\n input account id\n");
796         if (0 >= scanf("%d", &account_id))
797                 testapp_print("Invalid input. ");
798         email_get_password_length_of_account(account_id, EMAIL_GET_INCOMING_PASSWORD_LENGTH, &password_length);
799         testapp_print("testapp_test_get_password_length_of_account returned [%d]\n",password_length);
800         return FALSE;
801 }
802
803 static gboolean testapp_test_update_notification()
804 {
805         int error_code;
806         int account_id = 0;
807         int t_mail_count = 0;
808         int input_from_eas = 0;
809         int unread_mail_count = 0;
810
811         testapp_print("\n Input account ID:\n");
812         if (0 >= scanf("%d", &account_id))
813                 testapp_print("Invalid input. ");
814
815         testapp_print("\n Input mail count:\n");
816         if (0 >= scanf("%d", &t_mail_count))
817                 testapp_print("Invalid input. ");
818
819         testapp_print("\n Input unread mail count:\n");
820         if (0 >= scanf("%d", &unread_mail_count))
821                 testapp_print("Invalid input. ");
822
823         testapp_print("\n Input From eas:\n");
824         if (0 >= scanf("%d", &input_from_eas))
825                 testapp_print("Invalid input. ");
826
827         error_code = email_update_notification_bar(account_id, t_mail_count, unread_mail_count, input_from_eas);
828         testapp_print("email_update_notification_bar returned [%d]\n",error_code);
829         return FALSE;
830 }
831
832 static gboolean testapp_test_clear_notification()
833 {
834         int account_id = 0;
835         int error_code;
836
837         testapp_print("\n Input account ID:\n");
838         if (0 >= scanf("%d", &account_id))
839                 testapp_print("Invalid input. ");
840
841         error_code = email_clear_notification_bar(account_id);
842         testapp_print("email_clear_notification_bar returned [%d]\n",error_code);
843         return FALSE;
844 }
845
846 static gboolean testapp_test_clear_all_notification()
847 {
848         int error_code;
849
850         error_code = email_clear_notification_bar(ALL_ACCOUNT);
851         testapp_print("email_clear_notification_bar returned [%d]\n",error_code);
852         return FALSE;
853 }
854
855 static gboolean testapp_test_save_default_account_id()
856 {
857         int error_code;
858         int account_id = 0;
859
860         testapp_print ("\nInput default account id : ");
861
862         if (0 >= scanf("%d", &account_id))
863                 testapp_print("Invalid input. ");
864
865         error_code = email_save_default_account_id(account_id);
866
867         testapp_print("email_save_default_account_id returned [%d]\n",error_code);
868         return FALSE;
869 }
870
871 static gboolean testapp_test_load_default_account_id()
872 {
873         int error_code;
874         int account_id = 0;
875
876         error_code = email_load_default_account_id(&account_id);
877
878         testapp_print ("\ndefault account id : %d\n", account_id);
879         testapp_print("email_load_default_account_id returned [%d]\n",error_code);
880         return FALSE;
881 }
882
883 static gboolean testapp_test_add_certificate()
884 {
885         int ret = 0;
886         char save_name[50] = {0, };
887         char certificate_path[255] = {0, };
888
889         testapp_print("Input cert path : ");
890         if (0 >= scanf("%s", certificate_path))
891                 testapp_print("Invalid input. ");
892
893         testapp_print("Input cert email-address : ");
894         if (0 >= scanf("%s", save_name))
895                 testapp_print("Invalid input. ");
896
897         testapp_print("cert path : [%s]", certificate_path);
898         testapp_print("email-address : [%s]", save_name);
899
900         ret = email_add_certificate(certificate_path, save_name);
901         if (ret != EMAIL_ERROR_NONE) {
902                 testapp_print("Add certificate failed\n");
903                 return false;
904         }
905
906         testapp_print("Add certificate success\n");
907         return true;
908 }
909
910 static gboolean testapp_test_get_certificate()
911 {
912         int ret = 0;
913         char save_name[20] = {0, };
914         email_certificate_t *certificate = NULL;
915
916         testapp_print("Input cert email-address : ");
917         if (0 >= scanf("%s", save_name))
918                 testapp_print("Invalid input. ");
919
920         ret = email_get_certificate(save_name, &certificate);
921         if (ret != EMAIL_ERROR_NONE) {
922                 testapp_print("Get certificate failed\n");
923                 return false;
924         }
925
926         testapp_print("certificate_id : %d\n", certificate->certificate_id);
927         testapp_print("issue_year : %d\n", certificate->issue_year);
928         testapp_print("issue_month : %d\n", certificate->issue_month);
929         testapp_print("issue_day : %d\n", certificate->issue_day);
930         testapp_print("expiration_year : %d\n", certificate->expiration_year);
931         testapp_print("expiration_month : %d\n", certificate->expiration_month);
932         testapp_print("expiration_day : %d\n", certificate->expiration_day);
933         testapp_print("issue_organization_name : %s\n", certificate->issue_organization_name);
934         testapp_print("subject_string : %s\n", certificate->subject_str);
935         testapp_print("file path : %s\n", certificate->filepath);
936
937         if (certificate)
938                 email_free_certificate(&certificate, 1);
939
940         testapp_print("Get certificate success\n");
941         return true;
942 }
943
944 static gboolean testapp_test_delete_certificate()
945 {
946         int ret = 0;
947         char save_name[20] = {0, };
948
949         testapp_print("Input cert email-address : ");
950         if (0 >= scanf("%s", save_name))
951                 testapp_print("Invalid input. ");
952
953         ret = email_delete_certificate(save_name);
954         if (ret != EMAIL_ERROR_NONE) {
955                 testapp_print("Delete certificate failed\n");
956                 return false;
957         }
958
959         testapp_print("Delete certificate success\n");
960         return true;
961 }
962
963 static gboolean testapp_test_add_account()
964 {
965         int err = EMAIL_ERROR_NONE;
966         email_account_t *account = NULL;
967
968         if(!testapp_create_account_object(&account)) {
969                 testapp_print ("testapp_test_create_account_by_account_type error\n");
970                 return FALSE;
971         }
972
973         err = email_add_account(account);
974         if( err < 0) {
975                 testapp_print ("email_add_account error : %d\n", err);
976                 err = email_free_account(&account, 1);
977                 return FALSE;
978         }
979
980         testapp_print ("email_add_account succeed. account_id\n", account->account_id);
981
982         err = email_free_account(&account, 1);
983
984         return true;
985 }
986
987 static gboolean testapp_test_update_peak_schedule()
988 {
989         int account_id;
990         email_account_t *account = NULL;
991         int err = EMAIL_ERROR_NONE;
992
993         testapp_print("\n>> Enter Account No: ");
994         if (0 >= scanf("%d",&account_id))
995                 testapp_print("Invalid input. ");
996
997         if( (err = email_get_account(account_id, GET_FULL_DATA, &account)) != EMAIL_ERROR_NONE) {
998                 testapp_print ("email_get_account failed [%d]\n", err);
999                 return false;
1000         }
1001
1002         testapp_print ("old check_interval - %d \n", account->check_interval);
1003
1004         testapp_print("\n Enter new check interval (in mins):");
1005         if (0 >= scanf("%d",&(account->check_interval)))
1006                 testapp_print("Invalid input. ");
1007
1008         testapp_print ("old peak_interval - %d \n", account->peak_interval);
1009
1010         testapp_print("\n Enter new peak interval (in mins):");
1011         if (0 >= scanf("%d",&(account->peak_interval)))
1012                 testapp_print("Invalid input. ");
1013
1014         testapp_print ("old peak_days - %d \n", account->peak_days);
1015
1016         testapp_print("\n Enter new peak days:");
1017         if (0 >= scanf("%d",&(account->peak_days)))
1018                 testapp_print("Invalid input. ");
1019
1020         testapp_print ("old peak_start_time - %d \n", account->peak_start_time);
1021
1022         testapp_print("\n Enter new peak start time:");
1023         if (0 >= scanf("%d",&(account->peak_start_time)))
1024                 testapp_print("Invalid input. ");
1025
1026         testapp_print ("old peak_end_time - %d \n", account->peak_start_time);
1027
1028         testapp_print("\n Enter new peak end time:");
1029         if (0 >= scanf("%d",&(account->peak_end_time)))
1030                 testapp_print("Invalid input. ");
1031
1032         if( account )  {
1033                 if((err = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) {
1034                         testapp_print ("email_update_account failed [%d]\n", err);
1035                         return false;
1036                 }
1037                 testapp_print ("email_update_account successful \n");
1038         }
1039         return true;
1040 }
1041
1042 static gboolean testapp_test_interpret_command (int selected_number)
1043 {
1044         gboolean go_to_loop = TRUE;
1045         
1046         switch (selected_number) {
1047                 case 1:
1048                         testapp_test_add_account_with_validation();
1049                         break;
1050
1051                 case 2:
1052                         testapp_test_update_account();
1053                         break;
1054
1055                 case 3:
1056                         testapp_test_delete_account();
1057                         break;
1058
1059                 case 4:
1060                         testapp_test_get_account();
1061                         break;
1062                 
1063                 case 5:
1064                         testapp_test_get_account_list();
1065                         break;
1066
1067                 case 6:
1068                         testapp_test_update_check_interval();
1069                         break;
1070
1071                 case 7:
1072                         testapp_test_validate_account();
1073                         break;          
1074
1075                 case 8:
1076                         testapp_test_cancel_validate_account();
1077                         break;  
1078
1079                 case 9:
1080                         testapp_test_backup_account();
1081                         break;  
1082
1083                 case 10:
1084                         testapp_test_restore_account();
1085                         break;  
1086
1087                 case 11:
1088                         testapp_test_get_password_length_of_account();
1089                         break;
1090
1091                 case 13:
1092                         testapp_test_update_notification();
1093                         break;
1094
1095                 case 14:
1096                         testapp_test_clear_notification();
1097                         break;
1098
1099                 case 15:
1100                         testapp_test_clear_all_notification();
1101                         break;
1102
1103                 case 16:
1104                         testapp_test_save_default_account_id();
1105                         break;
1106
1107                 case 17:
1108                         testapp_test_load_default_account_id();
1109                         break;
1110
1111                 case 18:
1112                         testapp_test_add_certificate();
1113                         break;
1114
1115                 case 19:
1116                         testapp_test_get_certificate();
1117                         break;
1118
1119                 case 20:
1120                         testapp_test_delete_certificate();
1121                         break;
1122
1123                 case 21:
1124                         testapp_test_add_account();
1125                         break;
1126
1127                 case 22:
1128                         testapp_test_update_peak_schedule();
1129                         break;
1130
1131                 case 0:
1132                         go_to_loop = FALSE;
1133                         break;
1134
1135                 default:
1136                         break;
1137         }
1138
1139         return go_to_loop;
1140 }
1141
1142 void testapp_account_main ()
1143 {
1144         gboolean go_to_loop = TRUE;
1145         int menu_number = 0;
1146         
1147         while (go_to_loop) {
1148                 testapp_show_menu (EMAIL_ACCOUNT_MENU);
1149                 testapp_show_prompt (EMAIL_ACCOUNT_MENU);
1150
1151                 if (0 >= scanf("%d", &menu_number))
1152                         testapp_print("Invalid input");
1153
1154                 go_to_loop = testapp_test_interpret_command (menu_number);
1155         }       
1156 }
1157