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