Fixed the invalid casting and remove the flash noti
[platform/core/messaging/email-service.git] / utilities / test-application / testapp-mail.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
23
24 /* common header */
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <sys/stat.h>
29 #include <wait.h>
30
31 /* open header */
32 #include <glib.h>
33 #include <time.h>
34
35 #include "email-api-account.h"
36 #include "email-api-network.h"
37 #include "email-api-mail.h"
38 #include "email-api-mailbox.h"
39 #include "email-api-etc.h"
40 #include "email-api-smime.h"
41
42 /* internal header */
43 #include "testapp-utility.h"
44 #include "testapp-mail.h"
45 #include "email-core-utils.h"
46 #include "email-core-mime.h"
47
48 #define MAIL_TEMP_BODY "/tmp/utf8"
49 #define HTML_TEMP_BODY "/tmp/utf8.htm"
50
51 /*
52 static void testapp_test_print_sorting_menu()
53 {
54         testapp_print("   EMAIL_SORT_DATETIME_HIGH = 0\n");
55         testapp_print("   EMAIL_SORT_DATETIME_LOW = 1\n");      
56         testapp_print("   EMAIL_SORT_SENDER_HIGH = 2\n");
57         testapp_print("   EMAIL_SORT_SENDER_LOW = 3\n");   
58         testapp_print("   EMAIL_SORT_RCPT_HIGH = 4\n");
59         testapp_print("   EMAIL_SORT_RCPT_LOW = 5\n");    
60         testapp_print("   EMAIL_SORT_SUBJECT_HIGH = 6\n");
61         testapp_print("   EMAIL_SORT_SUBJECT_LOW = 7\n");   
62         testapp_print("   EMAIL_SORT_PRIORITY_HIGH = 8\n");
63         testapp_print("   EMAIL_SORT_PRIORITY_LOW = 9\n");   
64         testapp_print("   EMAIL_SORT_ATTACHMENT_HIGH = 10\n");
65         testapp_print("   EMAIL_SORT_ATTACHMENT_LOW = 11\n");   
66         testapp_print("   EMAIL_SORT_FAVORITE_HIGH = 12\n");
67         testapp_print("   EMAIL_SORT_FAVORITE_LOW = 13\n");   
68 }
69
70 static void testapp_test_print_mail_list_item(email_mail_list_item_t *mail_list_item, int count)
71 {
72         int i;
73         
74         testapp_print("\n>>>>> Print mail list items: count[%d]\n", count);
75         for (i=0; i< count; i++) {
76                 testapp_print("\n[%d]\n", i);
77                 testapp_print(" >>> Mailbox Name [ %s ] \n", mail_list_item[i].mailbox_name);
78                 testapp_print(" >>> Mail ID [ %d ] \n", mail_list_item[i].mail_id);
79                 testapp_print(" >>> Account ID [ %d ] \n", mail_list_item[i].account_id);
80                 if (  mail_list_item[i].from!= NULL ) {
81                         testapp_print(" >>> From [ %s ] \n", mail_list_item[i].from);
82                 }
83                 if (  mail_list_item[i].from_email_address != NULL ) {
84                         testapp_print(" >>> from_email_address [ %s ] \n", mail_list_item[i].from_email_address);
85                 }
86                 if (  mail_list_item[i].recipients!= NULL ) {
87                         testapp_print(" >>> recipients [ %s ] \n", mail_list_item[i].recipients);
88                 }
89                 if (  mail_list_item[i].subject != NULL ) {
90                         testapp_print(" >>> subject [ %s ] \n", mail_list_item[i].subject);
91                 }
92                 testapp_print(" >>> text_download_yn [ %d ] \n", mail_list_item[i].body_download_status);
93                 testapp_print(" >>> date_time [ %d ] \n", mail_list_item[i].date_time);
94                 testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list_item[i].flags_seen_field);
95                 testapp_print(" >>> priority [ %d ] \n", mail_list_item[i].priority);
96                 testapp_print(" >>> save_status [ %d ] \n", mail_list_item[i].save_status);
97                 testapp_print(" >>> lock [ %d ] \n", mail_list_item[i].lock_status);
98                 testapp_print(" >>> report_status [ %d ] \n", mail_list_item[i].report_status);
99                 testapp_print(" >>> recipients_count [ %d ] \n", mail_list_item[i].recipients_count);
100                 testapp_print(" >>> attachment_count [ %d ] \n", mail_list_item[i].attachment_count);
101                 testapp_print(" >>> DRM_status [ %d ] \n", mail_list_item[i].DRM_status);
102
103                 if (  mail_list_item[i].preview_text != NULL ) {
104                         testapp_print(" >>> preview_text [ %s ] \n", mail_list_item[i].preview_text);
105                 }
106
107                 testapp_print(" >>> thread_id [ %d ] \n", mail_list_item[i].thread_id);
108                 testapp_print(" >>> thread_item_count [ %d ] \n", mail_list_item[i].thread_item_count);
109         }
110 }
111 */
112
113 static gboolean testapp_add_mail_for_sending (int *result_mail_id)
114 {
115         int                    i = 0;
116         int                    account_id = 0;
117         int                    err = EMAIL_ERROR_NONE;
118         int                    smime_type = 0;
119         char                   recipient_address[300] = { 0 , };
120         char                   from_address[300] = { 0 , };
121         char                   passpharse[300] = {0, };
122         const char            *body_file_path = MAIL_TEMP_BODY;
123         
124         email_account_t       *account_data = NULL;
125         email_mailbox_t       *mailbox_data = NULL;
126         email_mail_data_t     *test_mail_data = NULL;
127         FILE                  *body_file;
128
129         testapp_print("\n > Enter account id : ");
130         if (0 >= scanf("%d", &account_id))
131                 testapp_print("Invalid input. ");
132
133         testapp_print("\n > Enter recipient address : ");
134         if (0 >= scanf("%s", recipient_address))
135                 testapp_print("Invalid input. ");
136
137         email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data);
138
139         email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_data);
140
141         test_mail_data = malloc(sizeof(email_mail_data_t));
142         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
143
144         SNPRINTF(from_address, 300, "<%s>", account_data->user_email_address);
145
146         test_mail_data->account_id             = account_id;
147         test_mail_data->save_status            = EMAIL_MAIL_STATUS_SEND_DELAYED;
148         test_mail_data->body_download_status   = 1;
149         test_mail_data->flags_seen_field       = 1;
150         test_mail_data->file_path_plain        = strdup(body_file_path);
151         test_mail_data->mailbox_id             = mailbox_data->mailbox_id;
152         test_mail_data->mailbox_type           = mailbox_data->mailbox_type;
153         test_mail_data->full_address_from      = strdup(from_address);
154         test_mail_data->full_address_to        = strdup(recipient_address);
155         test_mail_data->subject                = strdup("Read receipt request from TIZEN");
156         test_mail_data->remaining_resend_times = 3;
157         test_mail_data->report_status          = EMAIL_MAIL_REQUEST_DSN | EMAIL_MAIL_REQUEST_MDN;
158
159         body_file = fopen(body_file_path, "w");
160
161         testapp_print("\n body_file [%p]\n", body_file);
162
163         if(body_file == NULL) {
164                 testapp_print("\n fopen [%s]failed\n", body_file_path);
165                 return FALSE;
166         }
167
168         for(i = 0; i < 100; i++)
169                 fprintf(body_file, "Mail sending Test. [%d]\n", i);
170
171         fflush(body_file);
172         fclose(body_file);
173
174         testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt, 4: pgp sign, 5: pgp encrypted, 6: pgp sign + encrypt] : ");
175         if (0 >= scanf("%d", &smime_type))
176                 testapp_print("Invalid input. ");
177         test_mail_data->smime_type = smime_type;
178
179         if (smime_type >= EMAIL_PGP_SIGNED) {
180                 testapp_print(" > passpharse : ");
181                 if (0 >= scanf("%s", passpharse))
182                         testapp_print("Invalid input. ");
183                 test_mail_data->pgp_password = strdup(passpharse);
184         }
185
186         if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE)
187                 testapp_print("email_add_mail failed. [%d]\n", err);
188         else
189                 testapp_print("email_add_mail success.\n");
190
191         testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
192
193         if(result_mail_id)
194                 *result_mail_id = test_mail_data->mail_id;
195
196         email_free_mail_data(&test_mail_data, 1);
197         email_free_mailbox(&mailbox_data, 1);
198         email_free_account(&account_data, 1);
199
200         return FALSE;
201 }
202
203 static gboolean testapp_test_add_mail (int *result_mail_id)
204 {
205         int                    i = 0;
206         int                    account_id = 0;
207         int                    mailbox_id = 0;
208         int                    from_eas = 0;
209         int                    attachment_count = 0;
210         int                    err = EMAIL_ERROR_NONE;
211         int                    smime_type = 0;
212         char                   arg[50] = { 0 , };
213         const char            *body_file_path = MAIL_TEMP_BODY;
214         email_mailbox_t         *mailbox_data = NULL;
215         email_mail_data_t       *test_mail_data = NULL;
216         email_attachment_data_t *attachment_data = NULL;
217         email_meeting_request_t *meeting_req = NULL;
218         FILE                  *body_file;
219  
220         testapp_print("\n > Enter account id : ");
221         if (0 >= scanf("%d", &account_id))
222                 testapp_print("Invalid input. ");
223
224         memset(arg, 0x00, 50);
225         testapp_print("\n > Enter mailbox id : ");
226         if (0 >= scanf("%d", &mailbox_id))
227                 testapp_print("Invalid input. ");
228
229         email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox_data);
230
231         test_mail_data = malloc(sizeof(email_mail_data_t));
232         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
233         
234         testapp_print("\n From EAS? [0/1]> ");
235         if (0 >= scanf("%d", &from_eas))
236                 testapp_print("Invalid input. ");
237
238         test_mail_data->account_id             = account_id;
239         test_mail_data->save_status            = 1;
240         test_mail_data->body_download_status   = 1;
241         test_mail_data->flags_seen_field       = 1;
242         test_mail_data->file_path_plain        = strdup(body_file_path);
243         test_mail_data->mailbox_id             = mailbox_id;
244         test_mail_data->mailbox_type           = mailbox_data->mailbox_type;
245         test_mail_data->full_address_from      = strdup("<test1@test.com>");
246         test_mail_data->full_address_to        = strdup("<test2@test.com>");
247         test_mail_data->full_address_cc        = strdup("<test3@test.com>");
248         test_mail_data->full_address_bcc       = strdup("<test4@test.com>");
249         test_mail_data->subject                = strdup("Meeting request mail");
250         test_mail_data->remaining_resend_times = 3;
251         test_mail_data->eas_data               = strdup("EAS DATA TEST");
252         test_mail_data->eas_data_length        = strlen(test_mail_data->eas_data) + 1;
253
254         body_file = fopen(body_file_path, "w");
255
256         testapp_print("\n body_file [%p]\n", body_file);
257
258         if(body_file == NULL) {
259                 testapp_print("\n fopen [%s]failed\n", body_file_path);
260                 return FALSE;
261         }
262 /*      
263         for(i = 0; i < 500; i++)
264                 fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
265 */
266         fprintf(body_file, "Hello world");
267         fflush(body_file);
268         fclose(body_file);
269
270         testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrypt, 3: sing + encrypt] : ");
271         if (0 >= scanf("%d", &smime_type))
272                 testapp_print("Invalid input. ");
273         test_mail_data->smime_type = smime_type;
274         
275         testapp_print(" > How many file attachment? [>=0] : ");
276         if (0 >= scanf("%d",&attachment_count))
277                 testapp_print("Invalid input. ");
278         
279         test_mail_data->attachment_count  = attachment_count;
280         if ( attachment_count > 0 )
281                 attachment_data = calloc(attachment_count, sizeof(email_attachment_data_t));
282
283
284         for ( i = 0; i < attachment_count ; i++ ) {
285                 memset(arg, 0x00, 50);
286                 testapp_print("\n > Enter attachment name : ");
287                 if (0 >= scanf("%s", arg))
288                         testapp_print("Invalid input. ");
289
290                 attachment_data[i].attachment_name  = strdup(arg);
291                 
292                 memset(arg, 0x00, 50);
293                 testapp_print("\n > Enter attachment absolute path : ");
294                 if (0 >= scanf("%s",arg))
295                         testapp_print("Invalid input. ");
296                 
297                 attachment_data[i].attachment_path  = strdup(arg);
298                 attachment_data[i].save_status      = 1;
299                 attachment_data[i].mailbox_id       = test_mail_data->mailbox_id;
300         }
301         
302         testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
303         if (0 >= scanf("%d", (int*)&(test_mail_data->meeting_request_status)))
304                 testapp_print("Invalid input. ");
305         
306         if ( test_mail_data->meeting_request_status == 1 
307                 || test_mail_data->meeting_request_status == 2 ) {
308                 time_t current_time;
309                 /*  dummy data for meeting request */
310                 meeting_req = malloc(sizeof(email_meeting_request_t));
311                 memset(meeting_req, 0x00, sizeof(email_meeting_request_t));
312                 
313                 meeting_req->meeting_response     = 1;
314                 current_time = time(NULL);
315                 gmtime_r(&current_time, &(meeting_req->start_time));
316                 gmtime_r(&current_time, &(meeting_req->end_time));
317                 meeting_req->location = strdup("Seoul");
318                 meeting_req->global_object_id = strdup("abcdef12345");
319
320                 meeting_req->time_zone.offset_from_GMT = 9;
321                 strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
322                 gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
323                 meeting_req->time_zone.standard_bias = 3;
324                 
325                 strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
326                 gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
327                 meeting_req->time_zone.daylight_bias = 7;
328
329         }
330         
331         if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE)
332                 testapp_print("email_add_mail failed. [%d]\n", err);
333         else
334                 testapp_print("email_add_mail success.\n");
335
336         testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
337         testapp_print("saved mailbox id = [%d]\n", test_mail_data->mailbox_id);
338
339         if(result_mail_id)
340                 *result_mail_id = test_mail_data->mail_id;
341
342         if(attachment_data)
343                 email_free_attachment_data(&attachment_data, attachment_count);
344                 
345         if(meeting_req)
346                 email_free_meeting_request(&meeting_req, 1);
347                 
348         email_free_mail_data(&test_mail_data, 1);
349         email_free_mailbox(&mailbox_data, 1);
350
351         return FALSE;
352 }
353
354 static gboolean testapp_test_update_mail()
355 {
356         int                    mail_id = 0;
357         int                    err = EMAIL_ERROR_NONE;
358         int                    test_attachment_data_count = 0;
359         int                    ret = 0;
360         char                   arg[50];
361         email_mail_data_t       *test_mail_data = NULL;
362         email_attachment_data_t *test_attachment_data_list = NULL;
363         email_meeting_request_t *meeting_req = NULL;
364         
365         testapp_print("\n > Enter mail id : ");
366         if (0 >= scanf("%d", &mail_id))
367                 testapp_print("Invalid input. ");
368
369         email_get_mail_data(mail_id, &test_mail_data);
370
371         if (!test_mail_data) {
372                 testapp_print("email_get_mail_data() failed\n");
373                 return FALSE;
374         }
375
376         testapp_print("\n > Enter Subject: ");
377         if (0 >= scanf("%s", arg))
378                 testapp_print("Invalid input. ");
379
380         test_mail_data->subject= strdup(arg);
381
382         if (test_mail_data->attachment_count > 0) {
383                 if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) {
384                         testapp_print("email_get_attachment_data_list() failed [%d]\n", err);
385                         goto FINISH_OFF;
386                 }
387         }       
388
389         if ( test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST 
390                 || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE 
391                 || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
392                 
393                 if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMAIL_ERROR_NONE ) {
394                         testapp_print("email_get_meeting_request() failed [%d]\n", err);
395                         goto FINISH_OFF;
396                 }
397         
398                 testapp_print("\n > Enter meeting response: ");
399                 if (0 >= scanf("%d", (int*)&(meeting_req->meeting_response)))
400                         testapp_print("Invalid input. ");
401         }
402         
403         if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMAIL_ERROR_NONE) 
404                         testapp_print("email_update_mail failed.[%d]\n", err);
405                 else
406                         testapp_print("email_update_mail success\n");
407
408         ret = 1;
409
410 FINISH_OFF:
411
412         if(test_mail_data)
413                 email_free_mail_data(&test_mail_data, 1);
414                 
415         if(test_attachment_data_list) 
416                 email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count);
417                 
418         if(meeting_req)
419                 email_free_meeting_request(&meeting_req, 1);
420
421         if (!ret)
422                 return FALSE;
423
424         return TRUE;
425 }
426
427 static gboolean testapp_test_get_mails()
428 {
429         testapp_print("\n >>> testapp_test_get_mails : Entered \n");
430         email_mail_data_t *mails = NULL, **mails_pointer = NULL;
431         int mailbox_id = 0;
432         int count = 0, i = 0;
433         int account_id = 0;
434         int start_index =0;
435         int limit_count = 0;
436         int sorting = 0;
437         int err_code = EMAIL_ERROR_NONE;
438         int to_get_count = 0;
439         int is_for_thread_view = 0;
440         int list_type;
441         struct tm *temp_time_info;
442
443         testapp_print("\n > Enter Account_id (0 = all accounts) : ");
444         if (0 >= scanf("%d",&account_id))
445                 testapp_print("Invalid input. ");
446         testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :");
447         if (0 >= scanf("%d", &mailbox_id))
448                 testapp_print("Invalid input. ");
449
450         testapp_print("\n > Enter Sorting : ");
451         if (0 >= scanf("%d",&sorting))
452                 testapp_print("Invalid input. ");
453
454         testapp_print("\n > Enter Start index (starting at 0): ");
455         if (0 >= scanf("%d",&start_index))
456                 testapp_print("Invalid input. ");
457
458         testapp_print("\n > Enter max_count : ");
459         if (0 >= scanf("%d",&limit_count))
460                 testapp_print("Invalid input. ");
461
462         testapp_print("\n > For thread view : ");
463         if (0 >= scanf("%d",&is_for_thread_view))
464                 testapp_print("Invalid input. ");
465
466         testapp_print("\n > Mail count only (0:list 1:count): ");
467         if (0 >= scanf("%d",&to_get_count))
468                 testapp_print("Invalid input. ");
469
470         if(to_get_count)
471                 mails_pointer = NULL;
472         else
473                 mails_pointer = &mails;
474
475         if(is_for_thread_view == -2) {
476                 list_type = EMAIL_LIST_TYPE_LOCAL;
477         }
478         else if(is_for_thread_view == -1)
479                 list_type = EMAIL_LIST_TYPE_THREAD;
480         else
481                 list_type = EMAIL_LIST_TYPE_NORMAL;
482
483         /* Get mail list */
484         if(mailbox_id == 0) {
485                 testapp_print("Calling email_get_mails for all mailbox.\n");
486                 err_code = email_get_mails(account_id, 0, list_type, start_index, limit_count, sorting, mails_pointer, &count);
487                 if ( err_code < 0)
488                         testapp_print("email_get_mails failed - err[%d]\n", err_code);
489         }
490         else {
491                 testapp_print("Calling email_get_mails for %d mailbox_id.\n", mailbox_id);
492                 err_code = email_get_mails(account_id, mailbox_id, list_type, start_index, limit_count, sorting,  mails_pointer, &count);
493                 if ( err_code < 0)
494                         testapp_print("email_get_mails failed - err[%d]\n", err_code);
495         }
496         testapp_print("email_get_mails >>>>>>count - %d\n",count);
497
498         if (mails) {
499                 for (i=0; i< count; i++) {
500                         testapp_print("\n[%d]\n", i);
501                         testapp_print(" >>> mailbox_id [ %d ] \n", mails[i].mailbox_id);
502                         testapp_print(" >>> mail_id [ %d ] \n", mails[i].mail_id);
503                         testapp_print(" >>> account_id [ %d ] \n", mails[i].account_id);
504                         if (  mails[i].full_address_from != NULL )
505                                 testapp_print(" >>> full_address_from [ %s ] \n", mails[i].full_address_from);
506                         if (  mails[i].full_address_to != NULL )
507                                 testapp_print(" >>> recipients [ %s ] \n", mails[i].full_address_to);
508                         if (  mails[i].subject != NULL )
509                                 testapp_print(" >>> subject [ %s ] \n", mails[i].subject);
510                         testapp_print(" >>> body_download_status [ %d ] \n", mails[i].body_download_status);
511                         temp_time_info = localtime(&mails[i].date_time);
512                         testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
513                                                                         temp_time_info->tm_year + 1900,
514                                                                         temp_time_info->tm_mon+1,
515                                                                         temp_time_info->tm_mday,
516                                                                         temp_time_info->tm_hour,
517                                                                         temp_time_info->tm_min,
518                                                                         temp_time_info->tm_sec);
519                         testapp_print(" >>> flags_seen_field [ %d ] \n", mails[i].flags_seen_field);
520                         testapp_print(" >>> priority [ %d ] \n", mails[i].priority);
521                         testapp_print(" >>> save_status [ %d ] \n", mails[i].save_status);
522                         testapp_print(" >>> lock_status [ %d ] \n", mails[i].lock_status);
523                         testapp_print(" >>> attachment_count [ %d ] \n", mails[i].attachment_count);
524                         if (  mails[i].preview_text != NULL )
525                                 testapp_print(" >>> preview_text [ %s ] \n", mails[i].preview_text);
526                 }
527                 free(mails);
528         }
529
530         testapp_print(" >>> testapp_test_get_mails : End \n");
531         return 0;
532 }
533
534 #define TEMP_ARGUMENT_SIZE 4096
535
536 static gboolean testapp_test_mail_send (int *result_mail_id)
537 {
538         int                    added_mail_id = 0;
539         int                    err = EMAIL_ERROR_NONE;
540         int                    handle = 0;
541         email_mail_data_t     *result_mail_data = NULL;
542
543         testapp_add_mail_for_sending(&added_mail_id);
544         
545         if(added_mail_id) {
546                 email_get_mail_data(added_mail_id, &result_mail_data);
547
548                 testapp_print("Calling email_send_mail...\n");
549
550                 if( email_send_mail(added_mail_id, &handle) < 0) {
551                         testapp_print("Sending failed[%d]\n", err);
552                 }
553                 else  {
554                         testapp_print("Start sending. handle[%d]\n", handle);
555                 }
556
557                 email_free_mail_data(&result_mail_data, 1);
558         }
559
560         if(result_mail_id)
561                 *result_mail_id = added_mail_id;
562
563         return FALSE;
564 }
565
566 static gboolean testapp_test_get_mail_list_ex()
567 {
568         email_list_filter_t *filter_list = NULL;
569         email_list_sorting_rule_t *sorting_rule_list = NULL;
570         email_mail_list_item_t *result_mail_list = NULL;
571         int filter_rule_count = 0;
572         int sorting_rule_count = 0;
573         int result_mail_count = 0;
574         int err = EMAIL_ERROR_NONE;
575         int i = 0;
576         int sort_order = 0;
577
578         filter_rule_count = 3;
579
580         filter_list = malloc(sizeof(email_list_filter_t) * filter_rule_count);
581         memset(filter_list, 0 , sizeof(email_list_filter_t) * filter_rule_count);
582
583         filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
584         filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
585         filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
586         filter_list[0].list_filter_item.rule.key_value.integer_type_value  = 1;
587         filter_list[0].list_filter_item.rule.case_sensitivity              = false;
588
589         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
590         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_AND;
591
592         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
593         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_MAILBOX_TYPE;
594         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
595         filter_list[2].list_filter_item.rule.key_value.integer_type_value  = EMAIL_MAILBOX_TYPE_INBOX;
596         filter_list[2].list_filter_item.rule.case_sensitivity              = false;
597
598         /*filter_list[0].list_filter_item_type                                     = EMAIL_LIST_FILTER_ITEM_RULE_ATTACH;
599         filter_list[0].list_filter_item.rule_attach.target_attribute             = EMAIL_MAIL_ATTACH_ATTRIBUTE_ATTACHMENT_NAME;
600         filter_list[0].list_filter_item.rule_attach.rule_type                    = EMAIL_LIST_FILTER_RULE_INCLUDE;
601         filter_list[0].list_filter_item.rule_attach.key_value.string_type_value  = strdup("test");
602         filter_list[0].list_filter_item.rule_attach.case_sensitivity             = false;*/
603
604         /*
605         filter_list[0].list_filter_item_type                                  = EMAIL_LIST_FILTER_ITEM_RULE;
606         filter_list[0].list_filter_item.rule_fts.target_attribute             = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
607         filter_list[0].list_filter_item.rule_fts.rule_type                    = EMAIL_LIST_FILTER_RULE_EQUAL;
608         filter_list[0].list_filter_item.rule_fts.key_value.integer_type_value = 1;
609
610         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
611         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
612
613
614         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
615         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
616         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
617         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("2013");
618         filter_list[2].list_filter_item.rule.case_sensitivity              = false;
619
620
621         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
622         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
623
624         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
625         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_TO;
626         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
627         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
628         filter_list[2].list_filter_item.rule.case_sensitivity              = false;
629
630         filter_list[3].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
631         filter_list[3].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
632
633         filter_list[4].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
634         filter_list[4].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_CC;
635         filter_list[4].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
636         filter_list[4].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
637         filter_list[4].list_filter_item.rule.case_sensitivity              = false;
638
639         filter_list[5].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
640         filter_list[5].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
641
642         filter_list[6].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
643         filter_list[6].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_BCC;
644         filter_list[6].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
645         filter_list[6].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
646         filter_list[6].list_filter_item.rule.case_sensitivity              = false;
647
648         filter_list[7].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
649         filter_list[7].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
650
651         filter_list[8].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
652         filter_list[8].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_FROM;
653         filter_list[8].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
654         filter_list[8].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
655         filter_list[8].list_filter_item.rule.case_sensitivity              = false;
656         */
657
658         /*
659         filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
660         filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
661         filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
662         filter_list[0].list_filter_item.rule.key_value.integer_type_value  = 1;
663
664         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
665         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_AND;
666
667         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
668         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME;
669         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
670         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("INBOX");
671         filter_list[2].list_filter_item.rule.case_sensitivity              = true;
672         */
673         sorting_rule_count = 2;
674
675         sorting_rule_list = malloc(sizeof(email_list_sorting_rule_t) * sorting_rule_count);
676         memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * sorting_rule_count);
677 /*
678         sorting_rule_list[0].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_RECIPIENT_ADDRESS;
679         sorting_rule_list[0].key_value.string_type_value                   = strdup("minsoo.kimn@gmail.com");
680         sorting_rule_list[0].sort_order                                    = EMAIL_SORT_ORDER_TO_CCBCC;
681 */
682         testapp_print("\n Enter the sort_order :");
683         if (0 >= scanf("%d", &sort_order))
684                 testapp_print("Invalid input.");
685
686         sorting_rule_list[0].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
687         sorting_rule_list[0].sort_order                                    = sort_order;
688
689         sorting_rule_list[1].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_DATE_TIME;
690         sorting_rule_list[1].sort_order                                    = EMAIL_SORT_ORDER_DESCEND;
691
692         err = email_get_mail_list_ex(filter_list, filter_rule_count, sorting_rule_list, sorting_rule_count, -1, -1, &result_mail_list, &result_mail_count);
693
694         if(err == EMAIL_ERROR_NONE) {
695                 testapp_print("email_get_mail_list_ex succeed.\n");
696
697                 for(i = 0; i < result_mail_count; i++) {
698                         testapp_print("mail_id [%d], subject [%s], mailbox_type [%d] full_address_from [%s]\n", result_mail_list[i].mail_id, result_mail_list[i].subject, result_mail_list[i].mailbox_type, result_mail_list[i].full_address_from);
699                 }
700         }
701         else {
702                 testapp_print("email_get_mail_list_ex failed.\n");
703         }
704
705         email_free_list_filter(&filter_list, 3);
706
707         return FALSE;
708 }
709
710 static gboolean testapp_test_send_cancel ()
711 {
712         int num = 0;
713         int Y = 0;
714         int i = 0;
715         int j = 0;
716         int *mailIdList = NULL;
717         int mail_id = 0;
718
719         testapp_print("\n > Enter total Number of mail  want to send: ");
720         if (0 >= scanf("%d", &num))
721                 testapp_print("Invalid input. ");
722         mailIdList = (int *)malloc(sizeof(int)*num);
723         if(!mailIdList)
724                 return false ;
725         
726         for(i = 1;i <=num ; i++) {
727                 testapp_test_mail_send(&mail_id);
728                 
729                 testapp_print("mail_id[%d]",mail_id);
730
731                 mailIdList[i] = mail_id;
732                 testapp_print("mailIdList[%d][%d]",i,mailIdList[i]);
733
734                 mail_id = 0;
735                 testapp_print("\n > Do you want to cancel the send mail job '1' or '0': ");
736                 if (0 >= scanf("%d", &Y))
737                         testapp_print("Invalid input. ");
738                 if(Y == 1) {
739                         testapp_print("\n >Enter mail-id[1-%d] ",i);
740                         if (0 >= scanf("%d", &j))
741                                 testapp_print("Invalid input. ");
742                         testapp_print("\n mailIdList[%d] ",mailIdList[j]);      
743                         if(email_cancel_sending_mail( mailIdList[j]) < 0)
744                                 testapp_print("email_cancel_sending_mail failed..!");
745                         else
746                                 testapp_print("email_cancel_sending_mail success..!");
747                 }
748         }
749         return FALSE;
750 }
751
752 static gboolean testapp_test_delete()
753 {
754         int mail_id=0, account_id =0;
755         int mailbox_id = 0;
756         int err = EMAIL_ERROR_NONE;
757         int from_server = 0;
758
759         testapp_print("\n > Enter Account_id: ");
760         if (0 >= scanf("%d", &account_id))
761                 testapp_print("Invalid input. ");
762
763         testapp_print("\n > Enter Mail_id: ");
764         if (0 >= scanf("%d", &mail_id))
765                 testapp_print("Invalid input. ");
766         
767         testapp_print("\n > Enter Mailbox id: ");
768         if (0 >= scanf("%d", &mailbox_id))
769                 testapp_print("Invalid input. ");
770         
771         testapp_print("\n > Enter from_server: ");
772         if (0 >= scanf("%d", &from_server))
773                 testapp_print("Invalid input. ");
774
775         /* delete message */
776         if( (err = email_delete_mail(mailbox_id, &mail_id, 1, from_server)) < 0)
777                 testapp_print("\n email_delete_mail failed[%d]\n", err);
778         else
779                 testapp_print("\n email_delete_mail success\n");
780
781         return FALSE;
782 }
783
784 static gboolean testapp_test_update_mail_attribute()
785 {
786         int  err = EMAIL_ERROR_NONE;
787         int  i = 0;
788         int  account_id = 0;
789         int *mail_id_array = NULL;
790         int  mail_id_count = 0;
791         email_mail_attribute_type attribute_type;
792         email_mail_attribute_value_t attribute_value;
793
794         testapp_print("\n > Enter account_id: ");
795         if (0 >= scanf("%d", &account_id))
796                 testapp_print("Invalid input. ");
797
798         testapp_print("\n > Enter attribute_type: ");
799         if (0 >= scanf("%d", (int*)&attribute_type))
800                 testapp_print("Invalid input. ");
801
802         testapp_print("\n > Enter integer type value: ");
803         if (0 >= scanf("%d", (int*)&(attribute_value.integer_type_value)))
804                 testapp_print("Invalid input. ");
805
806         testapp_print("\n > Enter mail_id_count: ");
807         if (0 >= scanf("%d", &mail_id_count))
808                 testapp_print("Invalid input. ");
809
810         mail_id_count = (mail_id_count < 5000)?mail_id_count:5000;
811
812         if (mail_id_count > 0) {
813                 mail_id_array = malloc(sizeof(int) * mail_id_count);
814         }
815
816         for (i = 0; i < mail_id_count; i++) {
817                 testapp_print("\n > Enter mail id: ");
818                 if (0 >= scanf("%d", (mail_id_array + i)))
819                         testapp_print("Invalid input. ");
820         }
821
822         /* delete message */
823         if ((err = email_update_mail_attribute(account_id, mail_id_array, mail_id_count, attribute_type, attribute_value)) < EMAIL_ERROR_NONE)
824                 testapp_print("\n email_update_mail_attribute failed[%d]\n", err);
825         else
826                 testapp_print("\n email_update_mail_attribute success\n");
827
828         if (mail_id_array)
829                 free(mail_id_array);
830
831         return FALSE;
832 }
833
834 static gboolean testapp_test_move()
835 {
836         int mail_id[3];
837         int i = 0;
838         int mailbox_id = 0;
839         
840         for(i = 0; i< 3; i++) {
841                 testapp_print("\n > Enter mail_id: ");
842                 if (0 >= scanf("%d",&mail_id[i]))
843                         testapp_print("Invalid input. ");
844         }
845         
846         testapp_print("\n > Enter mailbox_id: ");
847         if (0 >= scanf("%d", &mailbox_id))
848                 testapp_print("Invalid input. ");
849
850         /* move mail */
851         email_move_mail_to_mailbox(mail_id, 3, mailbox_id);
852         return FALSE;
853 }
854
855 static gboolean testapp_test_delete_all()
856 {
857         int mailbox_id =0;
858         int err = EMAIL_ERROR_NONE;
859
860         testapp_print("\n > Enter mailbox_id: ");
861         if (0 >= scanf("%d",&mailbox_id))
862                 testapp_print("Invalid input. ");
863                                                 
864         /* delete all message */
865         if ( (err = email_delete_all_mails_in_mailbox(mailbox_id, 0)) < 0)
866                 testapp_print("email_delete_all_mails_in_mailbox failed [%d]\n", err);
867         else
868                 testapp_print("email_delete_all_mails_in_mailbox Success\n");   
869                                                                                                                         
870         return FALSE;
871 }
872
873
874 static gboolean testapp_test_add_attachment()
875 {       
876         int mail_id = 0;
877         char arg[100];
878         email_attachment_data_t attachment;
879         
880         testapp_print("\n > Enter Mail Id: ");
881         if (0 >= scanf("%d", &mail_id))
882                 testapp_print("Invalid input. ");
883
884         memset(&attachment, 0x00, sizeof(email_attachment_data_t));
885         memset(arg, 0x00, 100);
886         testapp_print("\n > Enter attachment name: ");
887         if (0 >= scanf("%s",arg))
888                 testapp_print("Invalid input. ");
889         
890         attachment.attachment_name = strdup(arg);
891         
892         memset(arg, 0x00, 100);
893         testapp_print("\n > Enter attachment absolute path: ");
894         if (0 >= scanf("%s",arg))
895                 testapp_print("Invalid input. ");
896
897         attachment.save_status = true;
898         attachment.attachment_path = strdup(arg);
899         if(email_add_attachment(mail_id, &attachment) < 0)
900                 testapp_print("email_add_attachment failed\n"); 
901         else
902                 testapp_print("email_add_attachment success\n");
903
904
905         return FALSE;
906
907 }
908
909 static gboolean testapp_test_set_deleted_flag()
910 {
911         int index = 0;
912         int account_id = 0;
913         int mail_ids[100] = { 0, };
914         int temp_mail_id = 0;
915         int err_code = EMAIL_ERROR_NONE;
916
917         testapp_print("\n >>> Input target account id: ");
918         if (0 >= scanf("%d", &account_id))
919                 testapp_print("Invalid input. ");
920
921         do {
922                 testapp_print("\n >>> Input target mail id ( Input 0 to terminate ) [MAX = 100]: ");
923                 if (0 >= scanf("%d", &temp_mail_id))
924                         testapp_print("Invalid input. ");
925                 mail_ids[index++] = temp_mail_id;
926         } while (temp_mail_id != 0);
927
928         err_code = email_set_flags_field(account_id, mail_ids, index, EMAIL_FLAGS_DELETED_FIELD, 1, true);
929         testapp_print("email_set_flags_field returns - err[%d]\n", err_code);
930
931         return 0;
932 }
933
934 static gboolean testapp_test_expunge_mails_deleted_flagged()
935 {
936         int mailbox_id = 0;
937         int on_server = 0;
938         int err_code = EMAIL_ERROR_NONE;
939         int handle = 0;
940
941         testapp_print("\n >>> Input target mailbox id: ");
942         if (0 >= scanf("%d", &mailbox_id))
943                 testapp_print("Invalid input. ");
944
945         testapp_print("\n >>> Expunge on server?: ");
946         if (0 >= scanf("%d", &on_server))
947                 testapp_print("Invalid input. ");
948
949         err_code = email_expunge_mails_deleted_flagged(mailbox_id, on_server, &handle);
950
951         testapp_print("email_expunge_mails_deleted_flagged returns - err[%d]\n", err_code);
952
953         return 0;
954 }
955
956 static gboolean testapp_test_send_read_receipt()
957 {
958         int read_mail_id = 0;
959         int receipt_mail_id = 0;
960         int err_code = EMAIL_ERROR_NONE;
961         int handle = 0;
962
963         testapp_print("\n >>> Input read mail id: ");
964         if (0 >= scanf("%d", &read_mail_id))
965                 testapp_print("Invalid input. ");
966
967         err_code = email_add_read_receipt(read_mail_id, &receipt_mail_id);
968
969         testapp_print("eamil_add_read_receipt returns receipt_mail_id [%d] - err[%d]\n", receipt_mail_id, err_code);
970         testapp_print("Calling email_send_mail...\n");
971
972         if( (err_code = email_send_mail(receipt_mail_id, &handle)) != EMAIL_ERROR_NONE) {
973                 testapp_print("Sending failed[%d]\n", err_code);
974         }
975         else  {
976                 testapp_print("Start sending. handle[%d]\n", handle);
977         }
978
979         return 0;
980 }
981
982 static gboolean testapp_test_delete_attachment()
983 {
984         int attachment_id = 0;
985         int err_code = EMAIL_ERROR_NONE;
986
987         testapp_print("\n >>> Input attachment id: ");
988         if (0 >= scanf("%d", &attachment_id))
989                 testapp_print("Invalid input. ");
990
991         if( (err_code = email_delete_attachment(attachment_id)) != EMAIL_ERROR_NONE) {
992                 testapp_print("email_delete_attachment failed[%d]\n", err_code);
993         }
994
995         return 0;
996 }
997
998 static gboolean testapp_test_get_mail_list()
999 {
1000         testapp_print("\n >>> testapp_test_get_mail_list : Entered \n");
1001         email_mail_list_item_t *mail_list = NULL, **mail_list_pointer = NULL;
1002         int mailbox_id = 0;
1003         int count = 0, i = 0;
1004         int account_id = 0;
1005         int start_index =0;
1006         int limit_count = 0;
1007         int sorting = 0;
1008         int err_code = EMAIL_ERROR_NONE;
1009         int to_get_count = 0;
1010         int is_for_thread_view = 0;
1011         int list_type;
1012         struct tm *temp_time_info;
1013
1014         testapp_print("\n > Enter Account_id (0 = all accounts) : ");
1015         if (0 >= scanf("%d",&account_id))
1016                 testapp_print("Invalid input. ");
1017
1018         testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :");
1019         if (0 >= scanf("%d", &mailbox_id))
1020                 testapp_print("Invalid input. ");
1021
1022         testapp_print("\n > Enter Sorting : ");
1023         if (0 >= scanf("%d",&sorting))
1024                 testapp_print("Invalid input. ");
1025         
1026         testapp_print("\n > Enter Start index (starting at 0): ");
1027         if (0 >= scanf("%d",&start_index))
1028                 testapp_print("Invalid input. ");
1029
1030         testapp_print("\n > Enter max_count : ");
1031         if (0 >= scanf("%d",&limit_count))
1032                 testapp_print("Invalid input. ");
1033
1034         testapp_print("\n > For thread view : ");
1035         if (0 >= scanf("%d",&is_for_thread_view))
1036                 testapp_print("Invalid input. ");
1037
1038         testapp_print("\n > Count mails?(1: YES):");
1039         if (0 >= scanf("%d",&to_get_count))
1040                 testapp_print("Invalid input. ");
1041
1042         if(to_get_count)
1043                 mail_list_pointer = NULL;
1044         else
1045                 mail_list_pointer = &mail_list;
1046         
1047         if(is_for_thread_view == -2) {
1048                 list_type = EMAIL_LIST_TYPE_LOCAL;
1049         }
1050         else if(is_for_thread_view == -1)
1051                 list_type = EMAIL_LIST_TYPE_THREAD;
1052         else
1053                 list_type = EMAIL_LIST_TYPE_NORMAL;
1054         
1055         /* Get mail list */
1056         if( mailbox_id == 0) {
1057                 testapp_print("Calling email_get_mail_list for all mailbox.\n");
1058                 err_code = email_get_mail_list(account_id, 0, list_type, start_index, limit_count, sorting,  mail_list_pointer, &count);
1059                 if ( err_code < 0) 
1060                         testapp_print("email_get_mail_list failed - err[%d]\n", err_code);
1061         }
1062         else {
1063                 testapp_print("Calling email_get_mail_list for %d mailbox_id.\n", mailbox_id);
1064                 err_code = email_get_mail_list(account_id, mailbox_id, list_type, start_index, limit_count, sorting,  mail_list_pointer, &count);
1065                 if ( err_code < 0) 
1066                         testapp_print("email_get_mail_list failed - err[%d]\n", err_code);
1067         }
1068         testapp_print("email_get_mail_list >>>>>>count - %d\n",count);
1069
1070         if (mail_list) {
1071                 for (i=0; i< count; i++) {
1072                         testapp_print("\n[%d]\n", i);
1073                         testapp_print(" >>> mailbox_id [ %d ] \n", mail_list[i].mailbox_id);
1074                         testapp_print(" >>> mailbox_type [ %d ] \n", mail_list[i].mailbox_type);
1075                         testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
1076                         testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
1077                         if (  mail_list[i].full_address_from != NULL )
1078                                 testapp_print(" >>> full_address_from [ %s ] \n", mail_list[i].full_address_from);
1079                         if (  mail_list[i].email_address_recipient != NULL )
1080                                 testapp_print(" >>> email_address_recipient [ %s ] \n", mail_list[i].email_address_recipient);
1081                         if (  mail_list[i].subject != NULL )
1082                                 testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
1083                         testapp_print(" >>> body_download_status [ %d ] \n", mail_list[i].body_download_status);
1084                         temp_time_info = localtime(&mail_list[i].date_time);
1085                         testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
1086                                                                 temp_time_info->tm_year + 1900,
1087                                                                 temp_time_info->tm_mon+1,
1088                                                                 temp_time_info->tm_mday,
1089                                                                 temp_time_info->tm_hour,
1090                                                                 temp_time_info->tm_min,
1091                                                                 temp_time_info->tm_sec);
1092                         testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
1093                         testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
1094                         testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
1095                         testapp_print(" >>> lock_status [ %d ] \n", mail_list[i].lock_status);
1096                         testapp_print(" >>> attachment_count [ %d ] \n", mail_list[i].attachment_count);
1097                         if (  mail_list[i].preview_text != NULL )
1098                                 testapp_print(" >>> preview_text [ %s ] \n", mail_list[i].preview_text);
1099                 }
1100                 free(mail_list);
1101         }
1102         
1103         testapp_print("\n >>> email_get_mail_list : End \n");
1104         return 0;
1105 }
1106
1107
1108 static gboolean testapp_test_get_mail_list_for_thread_view()
1109 {
1110         testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : Entered \n");
1111         email_mail_list_item_t *mail_list = NULL;
1112         int count = 0, i = 0;
1113         int account_id = 0;
1114         int mailbox_id = 0;
1115         int err_code = EMAIL_ERROR_NONE;
1116         struct tm *time_info;
1117
1118         testapp_print("\nEnter account id\n");
1119         if (0 >= scanf("%d",&account_id))
1120                 testapp_print("Invalid input. ");
1121
1122         testapp_print("\nEnter mailbox id\n");
1123         if (0 >= scanf("%d",&mailbox_id))
1124                 testapp_print("Invalid input. ");
1125
1126
1127         /* Get mail list */
1128         if ( email_get_mail_list(account_id, mailbox_id , EMAIL_LIST_TYPE_THREAD, 0, 500, EMAIL_SORT_DATETIME_HIGH, &mail_list, &count) < 0)  {
1129                 testapp_print("email_get_mail_list failed : %d\n",err_code);
1130                 return FALSE;
1131         }
1132         testapp_print("email_get_mail_list >>>>>>count - %d\n",count);
1133         if (mail_list) {
1134                 for (i=0; i< count; i++) {
1135                         testapp_print(" i [%d]\n", i);
1136                         testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
1137                         testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
1138                         testapp_print(" >>> mailbox_id [ %d ] \n", mail_list[i].mailbox_id);
1139                         testapp_print(" >>> full_address_from [ %s ] \n", mail_list[i].full_address_from);
1140                         testapp_print(" >>> email_address_recipient [ %s ] \n", mail_list[i].email_address_recipient);
1141                         testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
1142                         testapp_print(" >>> body_download_status [ %d ] \n", mail_list[i].body_download_status);
1143                         time_info = localtime(&mail_list[i].date_time);
1144                         testapp_print(" >>> date_time [ %s ] \n", asctime(time_info));
1145                         testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
1146                         testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
1147                         testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
1148                         testapp_print(" >>> lock [ %d ] \n", mail_list[i].lock_status);
1149                         testapp_print(" >>> attachment_count [ %d ] \n", mail_list[i].attachment_count);
1150                         testapp_print(" >>> preview_text [ %s ] \n", mail_list[i].preview_text);
1151                         testapp_print(" >>> thread_id [ %d ] \n", mail_list[i].thread_id);
1152                         testapp_print(" >>> thread__item_count [ %d ] \n", mail_list[i].thread_item_count);
1153                 }
1154                 free(mail_list);
1155         }       
1156         testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : End \n");
1157         return 0;
1158 }
1159
1160 static gboolean testapp_test_count ()
1161 {
1162         int total = 0;
1163         int unseen = 0;
1164         email_list_filter_t *filter_list = NULL;
1165
1166         filter_list = malloc(sizeof(email_list_filter_t) * 3);
1167         memset(filter_list, 0 , sizeof(email_list_filter_t) * 3);
1168
1169         filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
1170         filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
1171         filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
1172         filter_list[0].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
1173         filter_list[0].list_filter_item.rule.case_sensitivity              = false;
1174
1175         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
1176         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
1177
1178         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
1179         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_TO;
1180         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
1181         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
1182         filter_list[2].list_filter_item.rule.case_sensitivity              = false;
1183
1184         if(EMAIL_ERROR_NONE == email_count_mail(filter_list, 3, &total, &unseen))
1185                 printf("\n Total: %d, Unseen: %d \n", total, unseen);
1186         return 0;
1187 }
1188
1189 static gboolean testapp_test_move_mails_to_mailbox_of_another_account()
1190 {
1191         int  err = EMAIL_ERROR_NONE;
1192         int  mail_id_count = 0 ;
1193         int *mail_id_array = NULL;
1194         int  source_mailbox_id = 0;
1195         int  target_mailbox_id = 0;
1196         int  task_id = 0;
1197         int  i = 0;
1198
1199         testapp_print("\n > Enter source mailbox id: ");
1200         if (0 >= scanf("%d", &source_mailbox_id))
1201                 testapp_print("Invalid input. ");
1202
1203         testapp_print("\n > Enter target mailbox id: ");
1204         if (0 >= scanf("%d", &target_mailbox_id))
1205                 testapp_print("Invalid input. ");
1206
1207         testapp_print("\n > Enter mail count: ");
1208         if (0 >= scanf("%d", &mail_id_count))
1209                 testapp_print("Invalid input. ");
1210
1211         mail_id_count = (mail_id_count < 5000)?mail_id_count:5000;
1212
1213         if(mail_id_count > 0) {
1214                 mail_id_array = malloc(sizeof(int) * mail_id_count);
1215         }
1216
1217         for(i = 0; i < mail_id_count; i++) {
1218                 testapp_print("\n > Enter mail id: ");
1219                 if (0 >= scanf("%d", (mail_id_array + i)))
1220                         testapp_print("Invalid input. ");
1221         }
1222
1223         err = email_move_mails_to_mailbox_of_another_account(source_mailbox_id, mail_id_array, mail_id_count, target_mailbox_id, &task_id);
1224
1225         testapp_print("\nemail_move_mails_to_mailbox_of_another_account returns [%d], tast_id [%d] \n", err, task_id);
1226         return 0;
1227 }
1228
1229 static gboolean copy_file(char *input_source_path, char *input_dest_path)
1230 {
1231     int childExitStatus;
1232     pid_t pid;
1233     if (!input_source_path || !input_dest_path) {
1234         return FALSE;
1235     }
1236     testapp_print("copy_file started\n");
1237
1238     pid = fork();
1239
1240     if (pid == 0) {
1241         testapp_print("Copying file [%s] [%s]\n", input_source_path, input_dest_path);
1242         execl("/bin/cp", "/bin/cp", input_source_path, input_dest_path, (char *)0);
1243     }
1244     else {
1245         testapp_print("Wating child process\n");
1246         pid_t ws = waitpid( pid, &childExitStatus, WNOHANG);
1247         if (ws == -1)
1248         { /* error - handle as you wish */
1249                 testapp_print("waitpid returns error\n");
1250         }
1251
1252         if( WIFEXITED(childExitStatus)) /* exit code in childExitStatus */
1253         {
1254             WEXITSTATUS(childExitStatus); /* zero is normal exit */
1255             testapp_print("WEXITSTATUS\n");
1256             /* handle non-zero as you wish */
1257         }
1258         else if (WIFSIGNALED(childExitStatus)) /* killed */
1259         {
1260                 testapp_print("WIFSIGNALED\n");
1261         }
1262         else if (WIFSTOPPED(childExitStatus)) /* stopped */
1263         {
1264                 testapp_print("WIFSTOPPED\n");
1265         }
1266     }
1267     testapp_print("copy_file finished\n");
1268     return TRUE;
1269 }
1270
1271
1272 static gboolean testapp_test_send_mail_with_downloading_attachment_of_original_mail()
1273 {
1274         int err = EMAIL_ERROR_NONE;
1275         int original_mail_id = 0;
1276         int original_attachment_count = 0;
1277         int i = 0;
1278         int handle = 0;
1279         char *plain_text_path = MAIL_TEMP_BODY;
1280         char *html_file_path = HTML_TEMP_BODY;
1281         char new_subject[4086] = { 0, };
1282 /*      FILE *body_file; */
1283         email_mail_data_t *original_mail_data = NULL;
1284         email_mailbox_t *outbox = NULL;
1285         email_attachment_data_t *original_attachment_array = NULL;
1286
1287         testapp_print("\n > Enter original mail id: ");
1288         if (0 >= scanf("%d", &original_mail_id))
1289                 testapp_print("Invalid input. ");
1290
1291         /* Get original mail */
1292         if((err = email_get_mail_data(original_mail_id, &original_mail_data)) != EMAIL_ERROR_NONE || !original_mail_data) {
1293                 testapp_print("email_get_mail_data failed [%d]\n", err);
1294                 return FALSE;
1295         }
1296
1297         /* Get attachment of original mail */
1298         if((err = email_get_attachment_data_list(original_mail_id, &original_attachment_array, &original_attachment_count)) != EMAIL_ERROR_NONE || !original_attachment_array) {
1299                 testapp_print("email_get_attachment_data_list failed [%d]\n", err);
1300                 return FALSE;
1301         }
1302
1303         /* Remove attachment file path */
1304         for(i = 0; i < original_attachment_count; i++) {
1305                 original_attachment_array[i].save_status = 0;
1306                 if(original_attachment_array[i].attachment_path)
1307                         free(original_attachment_array[i].attachment_path);
1308                 original_attachment_array[i].attachment_path = NULL;
1309         }
1310
1311         /* Set reference mail id */
1312         original_mail_data->reference_mail_id = original_mail_data->mail_id;
1313         original_mail_data->body_download_status = 1;
1314
1315         /* Set from address */
1316         if(!original_mail_data->full_address_from) {
1317                 original_mail_data->full_address_from = strdup("<abc@abc.com>");
1318         }
1319
1320         /* Rewrite subject */
1321         if(original_mail_data->subject) {
1322                 snprintf(new_subject, 4086, "Fw:%s", original_mail_data->subject);
1323                 free(original_mail_data->subject);
1324                 original_mail_data->subject = NULL;
1325         }
1326         else {
1327                 snprintf(new_subject, 4086, "Forward test");
1328         }
1329
1330         original_mail_data->subject = strdup(new_subject);
1331
1332         /* Set mailbox information */
1333         if((err = email_get_mailbox_by_mailbox_type(original_mail_data->account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &outbox)) != EMAIL_ERROR_NONE || !outbox) {
1334                 testapp_print("email_get_mailbox_by_mailbox_type failed [%d]\n", err);
1335                 return FALSE;
1336         }
1337         original_mail_data->mailbox_id = outbox->mailbox_id;
1338         original_mail_data->mailbox_type = outbox->mailbox_type;
1339
1340         /* Copy body text */
1341         if(original_mail_data->file_path_html) {
1342                 copy_file(original_mail_data->file_path_html, html_file_path);
1343                 /*execl("/bin/cp", "/bin/cp", original_mail_data->file_path_html, html_file_path, (char *)0); */
1344                 free(original_mail_data->file_path_html);
1345                 original_mail_data->file_path_html = strdup(html_file_path);
1346         }
1347
1348         if(original_mail_data->file_path_plain) {
1349                 copy_file(original_mail_data->file_path_plain, plain_text_path);
1350                 /*execl("/bin/cp", "/bin/cp", original_mail_data->file_path_plain, plain_text_path, (char *)0);*/
1351                 free(original_mail_data->file_path_plain);
1352                 original_mail_data->file_path_plain = strdup(plain_text_path);
1353         }
1354
1355
1356         /*
1357         body_file = fopen(body_file_path, "w");
1358
1359         testapp_print("\n body_file [%p]\n", body_file);
1360
1361         if(body_file == NULL) {
1362                 testapp_print("\n fopen [%s]failed\n", body_file_path);
1363                 return FALSE;
1364         }
1365
1366         for(i = 0; i < 100; i++)
1367                 fprintf(body_file, "Mail sending Test. [%d]\n", i);
1368
1369         fflush(body_file);
1370         fclose(body_file);
1371         */
1372
1373         /* Add mail */
1374         if((err = email_add_mail(original_mail_data, original_attachment_array, original_attachment_count, NULL, false)) != EMAIL_ERROR_NONE) {
1375                 testapp_print("email_get_attachment_data_list failed [%d]\n", err);
1376                 return FALSE;
1377         }
1378
1379         /* Send mail */
1380         if((err = email_send_mail_with_downloading_attachment_of_original_mail(original_mail_data->mail_id, &handle)) != EMAIL_ERROR_NONE) {
1381                 testapp_print("email_send_mail_with_downloading_attachment_of_original_mail failed [%d]\n", err);
1382                 return FALSE;
1383         }
1384
1385         if(original_mail_data)
1386                 email_free_mail_data(&original_mail_data, 1);
1387
1388         if(outbox)
1389                 email_free_mailbox(&outbox, 1);
1390
1391         if(original_attachment_array)
1392                 email_free_attachment_data(&original_attachment_array, original_attachment_count);
1393
1394         return TRUE;
1395 }
1396
1397 static gboolean testapp_test_get_mail_data()
1398 {
1399         int err = EMAIL_ERROR_NONE;
1400         int mail_id = 0;
1401         email_mail_data_t *mail_data = NULL;
1402
1403         testapp_print("\n > Enter mail id: ");
1404         if (0 >= scanf("%d", &mail_id))
1405                 testapp_print("Invalid input. ");
1406
1407         /* Get original mail */
1408         if((err = email_get_mail_data(mail_id, &mail_data)) != EMAIL_ERROR_NONE || !mail_data) {
1409                 testapp_print("email_get_mail_data failed [%d]\n", err);
1410                 return FALSE;
1411         }
1412
1413         testapp_print("mail_id [%d]\n", mail_data->mail_id );
1414         testapp_print("account_id [%d]\n", mail_data->account_id);
1415         testapp_print("mailbox_id [%d]\n", mail_data->mailbox_id);
1416         testapp_print("mailbox_type [%d]\n", mail_data->mailbox_type);
1417         if(mail_data->subject)
1418                 testapp_print("subject [%s]\n", mail_data->subject );
1419         testapp_print("date_time [%d]\n", mail_data->date_time );
1420         testapp_print("server_mail_status [%d]\n", mail_data->server_mail_status);
1421
1422         if(mail_data->server_mailbox_name)
1423                 testapp_print("server_mailbox_name [%s]\n", mail_data->server_mailbox_name );
1424
1425         if(mail_data->server_mail_id)
1426                 testapp_print("server_mail_id [%s]\n", mail_data->server_mail_id);
1427
1428         if(mail_data->message_id)
1429                 testapp_print("message_id [%s]\n", mail_data->message_id);
1430
1431         testapp_print("reference_mail_id [%d]\n", mail_data->reference_mail_id );
1432
1433         if(mail_data->full_address_from)
1434                 testapp_print("full_address_from [%s]\n", mail_data->full_address_from );
1435
1436         if(mail_data->full_address_reply)
1437                 testapp_print("full_address_reply [%s]\n", mail_data->full_address_reply);
1438
1439         if(mail_data->full_address_to)
1440                 testapp_print("full_address_to [%s]\n", mail_data->full_address_to );
1441
1442         if(mail_data->full_address_cc)
1443                 testapp_print("full_address_cc [%s]\n", mail_data->full_address_cc );
1444
1445         if(mail_data->full_address_bcc)
1446                 testapp_print("full_address_bcc [%s]\n", mail_data->full_address_bcc);
1447
1448         if(mail_data->full_address_return)
1449                 testapp_print("full_address_return [%s]\n", mail_data->full_address_return );
1450
1451         if(mail_data->email_address_sender)
1452                 testapp_print("email_address_sender [%s]\n", mail_data->email_address_sender);
1453
1454         if(mail_data->email_address_recipient)
1455                 testapp_print("email_address_recipient [%s]\n", mail_data->email_address_recipient );
1456
1457         if(mail_data->alias_sender)
1458                 testapp_print("alias_sender [%s]\n", mail_data->alias_sender);
1459
1460         if(mail_data->alias_recipient)
1461                 testapp_print("alias_recipient [%s]\n", mail_data->alias_recipient );
1462
1463         testapp_print("body_download_status [%d]\n", mail_data->body_download_status);
1464
1465         if(mail_data->file_path_plain)
1466                 testapp_print("file_path_plain [%s]\n", mail_data->file_path_plain );
1467
1468         if(mail_data->file_path_html)
1469                 testapp_print("file_path_html [%s]\n", mail_data->file_path_html);
1470
1471         testapp_print("file_path_mime_entity [%s]\n", mail_data->file_path_mime_entity );
1472         testapp_print("mail_size [%d]\n", mail_data->mail_size );
1473         testapp_print("flags_seen_field [%d]\n", mail_data->flags_seen_field);
1474         testapp_print("flags_deleted_field [%d]\n", mail_data->flags_deleted_field );
1475         testapp_print("flags_flagged_field [%d]\n", mail_data->flags_flagged_field );
1476         testapp_print("flags_answered_field [%d]\n", mail_data->flags_answered_field);
1477         testapp_print("flags_recent_field [%d]\n", mail_data->flags_recent_field);
1478         testapp_print("flags_draft_field [%d]\n", mail_data->flags_draft_field );
1479         testapp_print("flags_forwarded_field [%d]\n", mail_data->flags_forwarded_field );
1480         testapp_print("DRM_status [%d]\n", mail_data->DRM_status);
1481         testapp_print("priority [%d]\n", mail_data->priority);
1482         testapp_print("save_status [%d]\n", mail_data->save_status );
1483         testapp_print("lock_status [%d]\n", mail_data->lock_status );
1484         testapp_print("report_status [%d]\n", mail_data->report_status );
1485         testapp_print("attachment_count [%d]\n", mail_data->attachment_count);
1486         testapp_print("inline_content_count [%d]\n", mail_data->inline_content_count);
1487         testapp_print("thread_id [%d]\n", mail_data->thread_id );
1488         testapp_print("thread_item_count [%d]\n", mail_data->thread_item_count );
1489
1490         if(mail_data->preview_text)
1491                 testapp_print("preview_text [%s]\n", mail_data->preview_text);
1492
1493         testapp_print("meeting_request_status [%d]\n", mail_data->meeting_request_status);
1494         testapp_print("message_class [%d]\n", mail_data->message_class);
1495         testapp_print("digest_type [%d]\n", mail_data->digest_type);
1496         testapp_print("smime_type [%d]\n", mail_data->smime_type);
1497         testapp_print("scheduled_sending_time [%d]\n", mail_data->scheduled_sending_time);
1498         testapp_print("remaining_resend_times [%d]\n", mail_data->remaining_resend_times);
1499         testapp_print("eas_data_length [%d]\n", mail_data->eas_data_length);
1500
1501         return TRUE;
1502 }
1503
1504 static gboolean testapp_test_schedule_sending_mail()
1505 {
1506         int                    added_mail_id = 0;
1507         int                    err = EMAIL_ERROR_NONE;
1508         int                    handle = 0;
1509         time_t                 time_to_send;
1510
1511         testapp_add_mail_for_sending(&added_mail_id);
1512
1513         if(added_mail_id) {
1514                 time(&time_to_send);
1515                 time_to_send += 60;
1516
1517                 testapp_print("Calling email_schedule_sending_mail...\n");
1518
1519                 if( email_schedule_sending_mail(added_mail_id, time_to_send) < 0) {
1520                         testapp_print("email_schedule_sending_mail failed[%d]\n", err);
1521                 }
1522                 else  {
1523                         testapp_print("Start sending. handle[%d]\n", handle);
1524                 }
1525         }
1526
1527         return TRUE;
1528 }
1529
1530 static gboolean testapp_test_set_flags_field ()
1531 {
1532         int account_id = 0;
1533         int mail_id = 0;
1534
1535         testapp_print("\n > Enter Account ID: ");
1536         if (0 >= scanf("%d", &account_id))
1537                 testapp_print("Invalid input. ");
1538         
1539         testapp_print("\n > Enter Mail ID: ");
1540         if (0 >= scanf("%d", &mail_id))
1541                 testapp_print("Invalid input. ");
1542
1543         if(email_set_flags_field(account_id, &mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, 1, 1) < 0)
1544                 testapp_print("email_set_flags_field failed");
1545         else
1546                 testapp_print("email_set_flags_field success");
1547                 
1548         return TRUE;
1549 }
1550
1551 static gboolean testapp_test_download_body ()
1552 {
1553         int mail_id = 0;
1554         int handle = 0, err;
1555
1556         testapp_print("\n > Enter Mail Id: ");
1557         if (0 >= scanf("%d", &mail_id))
1558                 testapp_print("Invalid input. ");
1559         err = email_download_body(mail_id, 0, &handle);
1560         if(err  < 0)
1561                 testapp_print("email_download_body failed");
1562         else {
1563                 testapp_print("email_download_body success");
1564                 testapp_print("handle[%d]\n", handle);
1565         }
1566         return TRUE;
1567 }
1568
1569
1570 static gboolean testapp_test_cancel_download_body ()
1571 {
1572         int mail_id = 0;
1573         int account_id = 0;
1574         int yes = 0;
1575         int handle = 0;
1576         
1577         email_mailbox_t mailbox;
1578         memset(&mailbox, 0x00, sizeof(email_mailbox_t));
1579
1580         testapp_print("\n > Enter account_id: ");
1581         if (0 >= scanf("%d", &account_id))
1582                 testapp_print("Invalid input. ");
1583
1584         testapp_print("\n > Enter mail id: ");
1585         if (0 >= scanf("%d", &mail_id))
1586                 testapp_print("Invalid input. ");
1587         
1588         if( email_download_body(mail_id, 0, &handle) < 0)
1589                 testapp_print("email_download_body failed");
1590         else {
1591                 testapp_print("email_download_body success\n");
1592                 testapp_print("Do u want to cancel download job>>>>>1/0\n");
1593                 if (0 >= scanf("%d",&yes))
1594                         testapp_print("Invalid input. ");
1595                 if(1 == yes) {
1596                         if(email_cancel_job(account_id, handle , EMAIL_CANCELED_BY_USER) < 0)
1597                                 testapp_print("email_cancel_job failed..!");
1598                         else {
1599                                 testapp_print("email_cancel_job success..!");
1600                                 testapp_print("handle[%d]\n", handle);
1601                         }
1602                 }
1603                         
1604         }
1605         return TRUE;
1606 }
1607 static gboolean testapp_test_download_attachment ()
1608 {
1609         int mail_id = 0;
1610         int attachment_no = 0;
1611         int handle = 0;
1612         
1613         testapp_print("\n > Enter Mail Id: ");
1614         if (0 >= scanf("%d", &mail_id))
1615                 testapp_print("Invalid input. ");
1616
1617         testapp_print("\n > Enter attachment number: ");
1618         if (0 >= scanf("%d", &attachment_no))
1619                 testapp_print("Invalid input. ");
1620         
1621         if( email_download_attachment(mail_id, attachment_no ,&handle) < 0)
1622                 testapp_print("email_download_attachment failed");
1623         else {
1624                 testapp_print("email_download_attachment success");
1625                 testapp_print("handle[%d]\n", handle);
1626         }
1627         return TRUE;
1628
1629 }
1630
1631 static gboolean testapp_test_get_attachment_data_list()
1632 {
1633         int err = EMAIL_ERROR_NONE;
1634         int i = 0;
1635         int mail_id = 0;
1636         int test_attachment_data_count;
1637         email_attachment_data_t *test_attachment_data_list = NULL;
1638
1639         testapp_print("\n > Enter Mail id: ");
1640         if (0 >= scanf("%d", &mail_id))
1641                 testapp_print("Invalid input. ");
1642
1643         if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) {
1644                 testapp_print("email_get_attachment_data_list() failed [%d]\n", err);
1645                 goto FINISH_OFF;
1646         }
1647         if(test_attachment_data_list) {
1648                 for(i = 0; i < test_attachment_data_count; i++) {
1649                         testapp_print("index [%d]\n", i);
1650                         testapp_print("attachment_name [%s]\n", test_attachment_data_list[i].attachment_name);
1651                         testapp_print("attachment_path [%s]\n", test_attachment_data_list[i].attachment_path);
1652                         testapp_print("attachment_size [%d]\n", test_attachment_data_list[i].attachment_size);
1653                         testapp_print("mail_id [%d]\n", test_attachment_data_list[i].mail_id);
1654                         testapp_print("attachment_mime_type [%s]\n", test_attachment_data_list[i].attachment_mime_type);
1655                 }
1656                 email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count);
1657         }
1658
1659 FINISH_OFF:
1660
1661         return TRUE;
1662 }
1663
1664 static gboolean testapp_test_get_meeting_request()
1665 {
1666         int mail_id = 0;
1667         int err = EMAIL_ERROR_NONE;
1668         email_meeting_request_t *meeting_request;
1669
1670         testapp_print("\n > Enter Mail Id: ");
1671         if (0 >= scanf("%d", &mail_id))
1672                 testapp_print("Invalid input. ");
1673
1674         err = email_get_meeting_request(mail_id, &meeting_request);
1675
1676         testapp_print("err[%d]\n", err);
1677
1678         if(err == EMAIL_ERROR_NONE && meeting_request) {
1679                 testapp_print("mail_id [%d]\n", meeting_request->mail_id);
1680                 testapp_print("global_object_id [%s]\n", meeting_request->global_object_id);
1681                 testapp_print("meeting_response [%d]\n", meeting_request->meeting_response);
1682         }
1683
1684         email_free_meeting_request(&meeting_request, 1);
1685         return TRUE;
1686 }
1687
1688 static gboolean testapp_test_retry_send()
1689 {
1690         int mail_id = 0;
1691         int timeout = 0;
1692         
1693         email_mailbox_t mailbox;
1694         memset(&mailbox, 0x00, sizeof(email_mailbox_t));
1695
1696         testapp_print("\n > Enter Mail Id: ");
1697         if (0 >= scanf("%d", &mail_id))
1698                 testapp_print("Invalid input. ");
1699         
1700         testapp_print("\n > Enter timeout in seconds: ");
1701         if (0 >= scanf("%d", &timeout))
1702                 testapp_print("Invalid input. ");
1703
1704         if( email_retry_sending_mail(mail_id, timeout) < 0)
1705                 testapp_print("email_retry_sending_mail failed");               
1706         return TRUE;            
1707 }
1708
1709 static gboolean testapp_test_get_attachment_data()
1710 {
1711         int attachment_id = 0;
1712         email_attachment_data_t *attachment = NULL;
1713
1714         testapp_print("\n > Enter attachment id: ");
1715         if (0 >= scanf("%d", &attachment_id))
1716                 testapp_print("Invalid input. ");
1717
1718         email_get_attachment_data(attachment_id, &attachment);
1719
1720         if(attachment) {
1721                 testapp_print("attachment_name [%s]\n", attachment->attachment_name);
1722                 testapp_print("attachment_path [%s]\n", attachment->attachment_path);
1723                 testapp_print("attachment_size [%d]\n", attachment->attachment_size);
1724                 testapp_print("mail_id [%d]\n", attachment->mail_id);
1725                 testapp_print("attachment_mime_type [%s]\n", attachment->attachment_mime_type);
1726         }
1727
1728         return TRUE;
1729 }
1730
1731 static gboolean testapp_test_move_all_mails_to_mailbox()
1732 {
1733         int err = EMAIL_ERROR_NONE;
1734         int src_mailbox_id;
1735         int dest_mailbox_id;
1736
1737         testapp_print("src mailbox id> ");
1738         if (0 >= scanf("%d", &src_mailbox_id))
1739                 testapp_print("Invalid input. ");
1740
1741         testapp_print("dest mailbox id> ");
1742         if (0 >= scanf("%d", &dest_mailbox_id))
1743                 testapp_print("Invalid input. ");
1744         
1745         err = email_move_all_mails_to_mailbox(src_mailbox_id, dest_mailbox_id);
1746         if ( err < 0 ) {
1747                 testapp_print("email_move_all_mails_to_mailbox failed: err[%d]\n", err);
1748         }
1749         else {
1750                 testapp_print("email_move_all_mails_to_mailbox suceeded\n");
1751         }
1752
1753         return false;
1754 }
1755
1756 static gboolean testapp_test_get_totaldiskusage()
1757 {
1758         unsigned long total_size = 0;
1759         int err_code = EMAIL_ERROR_NONE ;
1760         
1761         err_code = email_get_disk_space_usage(&total_size);
1762         if ( err_code < 0)
1763                 testapp_print("email_get_disk_space_usage failed err : %d\n",err_code);
1764         else
1765                 testapp_print("email_get_disk_space_usage SUCCESS, total disk usage in KB : %ld \n", total_size);               
1766
1767         return FALSE;
1768 }
1769
1770
1771
1772 static gboolean testapp_test_db_test()
1773 {
1774         int err = EMAIL_ERROR_NONE;
1775         int mail_id;
1776         int account_id;
1777         char *to = NULL;
1778         char *cc = NULL;
1779         char *bcc = NULL;
1780
1781         to = (char *) malloc(500000);
1782         cc = (char *) malloc(500000);
1783         bcc = (char *) malloc(500000);
1784         
1785         memset(to, 0x00, sizeof(500000));
1786         memset(cc, 0x00, sizeof(500000));
1787         memset(bcc, 0x00, sizeof(500000));
1788
1789         testapp_print("Input Mail id:\n");
1790         if (0 >= scanf("%d", &mail_id))
1791                 testapp_print("Invalid input. ");
1792         testapp_print("Input Account id:\n");
1793         if (0 >= scanf("%d", &account_id))
1794                 testapp_print("Invalid input. ");
1795         testapp_print("Input TO field:\n");
1796         if (0 >= scanf("%s", to))
1797                 testapp_print("Invalid input. ");
1798         testapp_print("Input CC field:\n");
1799         if (0 >= scanf("%s", cc))
1800                 testapp_print("Invalid input. ");
1801         testapp_print("Input BCC field:\n");
1802         if (0 >= scanf("%s", bcc))
1803                 testapp_print("Invalid input. ");
1804
1805         if ( emstorage_test(NULL, mail_id, account_id, to, cc, bcc, &err) == true ) {
1806                 testapp_print(">> Saving Succeeded\n");
1807         }
1808         else {
1809                 testapp_print(">> Saving Failed[%d]\n", err);
1810         }
1811         
1812         free(to);
1813         free(cc);
1814         free(bcc);
1815         
1816         return false;
1817 }
1818
1819 static gboolean testapp_test_address_format_check_test()
1820 {
1821         /*
1822         int i;
1823         int type;
1824         int index;
1825         int check_yn;
1826         int err = EMAIL_ERROR_NONE;
1827         char *pAddress = NULL;
1828         char input_address[8096];
1829         char *address_list[] = {
1830                 "tom@gmail.com",
1831                 "tom@gmail,com",
1832                 "tom@gmail.com@gmail.com",
1833                 "[tom@gmail.com]",
1834                 "\"Tom\"<tom@gmail.com>", 
1835                 "\"Tom\"[tom@gmail.com]",
1836                 "\"Tom\"<tom,@gmail.com>",
1837                 "<tom@gmail.com>",
1838                 "<tom@gmail,com>",
1839                 "<tom@gmail.>",
1840                 "<tom@gmail.com>,tom@gmail.com",
1841                 "<tom@gmail.com>;tom@gmail.com",
1842                 "tom @gmail.com",
1843                 "tom@ gmail.com",
1844                 "tom@gmail..com",
1845                 "tom@",
1846                 "tom@gmail",
1847                 "tom@gmail.",
1848                 "tom@gmail.c",
1849                 "tom@.",
1850                 "\"\"Tom\"<tom,@gmail.com>",
1851                 "tom@gmail.com,tom@gmail.com",
1852                 "tom@gmail.com.",
1853                 "<tom@gmail.com>,tom@.gmail.com",
1854                 "&& tom@live.com ----",
1855                 "madhu <tom@gmail.com>",
1856                 "tom@gmail.com, && tom@live.com",
1857                 "tom@gmail.com , && tom@live.com",
1858                 "< tom@gmail.com    > , <           tom@.gmail.com     >",
1859                 "tom@gmail.com ,           tom@gmail.com",
1860                 "<tom@gmail.com          >",
1861                 "<to     m@gmail.com          >",
1862                 "<tom@gmail.com>;tom@gmail.com",        
1863                "Tom< tom@gmail.com > ,       Tom <tom@gmail.com>",      
1864                 " \"Tom\"  < tom@gmail.com>  ,  \"Tom\"   < tom@gmail.com> ,  Tom  < tom@gmail.com> ; Tom  < tom@gmail.com>,\"tomtom\" <   tom@aol.com>,\"tomtom\" <   tom@aol.com>    ,\"tomtom\" <tom@aol.com>;<tom@live.com>,  <tom@live.com>; \"tomtomtomtom\" <tom@live.com>  ; \"tomtomtomtom\" <tom@live.com>,\"Tom\"  < tom@gmail.com>",
1865                 "<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>",
1866                 "             tom@gmail.com         ;   <  tom@gmail.com   > ",
1867                 "\"Tom\" <        tom@gmail.com >  ;  mama <  tom@gmail.com    >  ,   abcd@gmail.com     ,   abc@gmail.com ,\"tomtom\" <tom@aol.com>,\"tomtom\"  < tom@aol.com> ;\"tomtom\" <   tom@aol.com   >    ,\"tomtom\" <tom@aol.com> , \"tomtomtomtom\" <tom@live.com>  ",
1868                 "             \"tomtom\" <tom@aol.com>    ;\"tomtom\" <tom@aol.com> ;          ",
1869                 "  tom@gmail.com  ,   tom@gmail.com ,   tom@gmail.com; Tom  < tom@gmail.com   >  ,<   tom@aol.com>, <tom@aol.com>    ,<tom@aol.com>;<tom@live.com>,  tom@live.com;tom@live.com; \"tomtomtomtom\" <tom@live.com>,\"Tom\"  < tom@gmail.com> ;    ",
1870                 "<tom@aol.com>    , \"tomtomtomtom\" <tom@live.com>,\"Tom\"  < tom@gmail.com> ;    ",
1871                 " Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <   tom@gmail.com>  ,<tom@gmail.com>,Tom <tom@gmail.com       >,Tom< tom@gmail.com > ,       Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>",
1872                 NULL
1873         };
1874         int address_count = 0;
1875         
1876         testapp_print("Select input method:\n");
1877         testapp_print("1. Test data\n");
1878         testapp_print("2. Keyboard\n");
1879         if (0 >= scanf("%d", &type);
1880
1881         switch ( type ) {
1882                 case 1:
1883                         do  {
1884                                 for ( i = 0; address_list[i] != NULL; i++ ) {
1885                                         testapp_print("[%d] addr[%s]\n", i, address_list[i]);
1886                                         address_count++;
1887                                 }
1888                                 testapp_print("Choose address to be tested:[99:quit]\n");
1889                                 if (0 >= scanf("%d", &index);
1890                                 if ( index == 99 )
1891                                         break;
1892
1893                                 testapp_print(">> [%d] Checking? (1:Yes, Other:No) [%s]\n", index, address_list[index]);
1894                                 if (0 >= scanf("%d", &check_yn);
1895                                 if ( check_yn == 1 ) {
1896                                         pAddress = strdup(address_list[index]);
1897                                         if ( em_verify_email_address(pAddress, false, &err ) == true ) {
1898                                                 testapp_print("<< [%d] Checking Succeeded : addr[%s]\n", index, address_list[index]);
1899                                         }
1900                                         else {
1901                                                 testapp_print("<< [%d] Checking Failed    : addr[%s], err[%d]\n", index, address_list[index], err);
1902                                         }                       
1903                                         if(pAddress) {
1904                                                 free(pAddress);
1905                                                 pAddress = NULL;
1906                                         }
1907                                 }
1908                                 else {
1909                                         testapp_print("<< [%d]  Skipped            : addr[%s]\n", index, address_list[index]);
1910                                 }
1911                         } 
1912                         while (1);
1913                         break;
1914                 case 2:
1915                         testapp_print("Input address: \n");
1916                         if (0 >= scanf("%s", input_address);
1917                         if ( em_verify_email_address(input_address, false, &err ) == true ) {
1918                                 testapp_print(">> Saving Succeeded : addr[%s]\n", input_address);
1919                         }
1920                         else {
1921                                 testapp_print(">> Saving Failed : addr[%s], err[%d]\n", input_address, err);
1922                         }
1923                         break;
1924                 default:
1925                         testapp_print("wrong nuber... [%d]\n", type);
1926                         break;
1927         }
1928         */
1929         return FALSE;
1930 }
1931
1932 static gboolean testapp_test_get_max_mail_count()
1933 {
1934         int max_count = -1;
1935         int err = EMAIL_ERROR_NONE;
1936
1937         err = email_get_max_mail_count(&max_count);
1938         testapp_print("\n\t>>>>> email_get_max_mail_count() return [%d][%d]\n\n", max_count, err);
1939         
1940         return TRUE;
1941 }
1942
1943 #include "email-storage.h"
1944 static gboolean testapp_test_test_get_thread_information()
1945 {
1946         int error_code, thread_id= 38;
1947         email_mail_list_item_t *result_mail;
1948         
1949         if( (error_code = email_get_thread_information_ex(thread_id, &result_mail)) == EMAIL_ERROR_NONE) {
1950                 testapp_print("email_get_thread_information returns = %d\n", error_code);
1951                 testapp_print("subject = %s\n", result_mail->subject);
1952                 testapp_print("mail_id = %d\n", result_mail->mail_id);
1953                 testapp_print("full_address_from = %s\n", result_mail->full_address_from);
1954                 testapp_print("thrad_id = %d\n", result_mail->thread_id);
1955                 testapp_print("count = %d\n", result_mail->thread_item_count);
1956         }
1957
1958         return TRUE;
1959 }
1960
1961 static gboolean testapp_test_get_address_info_list()
1962 {
1963         testapp_print(" >>> testapp_test_get_address_info_list : Entered \n");
1964
1965         char buf[1024];
1966         int i = 0;
1967         int mail_id = 0;
1968         email_address_info_list_t *address_info_list= NULL;
1969         email_address_info_t *p_address_info = NULL;
1970         GList *list = NULL;
1971         GList *node = NULL;
1972
1973         memset(buf, 0x00, sizeof(buf));
1974         testapp_print("\n > Enter mail_id: ");
1975         if (0 >= scanf("%d",&mail_id))
1976                 testapp_print("Invalid input. ");
1977
1978         email_get_address_info_list(mail_id, &address_info_list);
1979
1980         testapp_print("===================================================\n");
1981         testapp_print("\t\t\t address info list\n");
1982         testapp_print("===================================================\n");
1983         testapp_print("address_type\t address \t\tdisplay_name\t contact id\n");
1984         testapp_print("===================================================\n");
1985
1986         for ( i = EMAIL_ADDRESS_TYPE_FROM; i <= EMAIL_ADDRESS_TYPE_BCC; i++ ) {
1987                 switch ( i ) {
1988                         case EMAIL_ADDRESS_TYPE_FROM:
1989                                 list = address_info_list->from;
1990                                 break;
1991                         case EMAIL_ADDRESS_TYPE_TO:
1992                                 list = address_info_list->to;
1993                                 break;
1994                         case EMAIL_ADDRESS_TYPE_CC:
1995                                 list = address_info_list->cc;
1996                                 break;
1997                         case EMAIL_ADDRESS_TYPE_BCC:
1998                                 list = address_info_list->bcc;
1999                                 break;
2000                 }
2001
2002                 /*  delete dynamic-allocated memory for each item */
2003                 node = g_list_first(list);
2004                 while ( node != NULL ) {
2005                         p_address_info = (email_address_info_t*)node->data;
2006                         testapp_print("%d\t\t%s\t%s\t%d\n", p_address_info->address_type, p_address_info->address, p_address_info->display_name, p_address_info->contact_id);
2007
2008                         node = g_list_next(node);
2009                 }
2010                 testapp_print("\n");
2011         }
2012         testapp_print("===================================================\n");
2013
2014         if(address_info_list)
2015                 email_free_address_info_list(&address_info_list);
2016
2017         testapp_print(" >>> testapp_test_get_address_info_list : END \n");
2018         return TRUE;
2019 }
2020
2021 static gboolean testapp_test_search_mail_on_server()
2022 {
2023         testapp_print(" >>> testapp_test_search_mail_on_server : Entered \n");
2024
2025         int err_code = EMAIL_ERROR_NONE;
2026         int account_id = 0;
2027         int mailbox_id = 0;
2028         int search_key_value_integer = 0;
2029         int search_filter_count = 0;
2030         email_search_filter_type search_filter_type = 0;
2031         email_search_filter_t search_filter[10];
2032         int handle = 0;
2033         time_t current_time = 0;
2034         char search_key_value_string[MAX_EMAIL_ADDRESS_LENGTH];
2035
2036         testapp_print("input account id : ");
2037         if (0 >= scanf("%d",&account_id))
2038                 testapp_print("Invalid input. ");
2039
2040         testapp_print("input mailbox id : ");
2041         if (0 >= scanf("%d", &mailbox_id))
2042                 testapp_print("Invalid input. ");
2043
2044         memset(&search_filter, 0x00, sizeof(email_search_filter_t) * 10);
2045
2046         while (1) {
2047                 testapp_print(
2048                         "       EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO       =  1,  ( integer type ) \n"
2049                         "       EMAIL_SEARCH_FILTER_TYPE_UID              =  2,  ( integer type ) \n"
2050                         "       EMAIL_SEARCH_FILTER_TYPE_ALL              =  3,  ( integer type ) \n"
2051                         "       EMAIL_SEARCH_FILTER_TYPE_BCC              =  7,  ( string type ) \n"
2052                         "       EMAIL_SEARCH_FILTER_TYPE_BODY             =  8,  ( string type ) \n"
2053                         "       EMAIL_SEARCH_FILTER_TYPE_CC               =  9,  ( string type ) \n"
2054                         "       EMAIL_SEARCH_FILTER_TYPE_FROM             = 10,  ( string type ) \n"
2055                         "       EMAIL_SEARCH_FILTER_TYPE_KEYWORD          = 11,  ( string type ) \n"
2056                         "       EMAIL_SEARCH_FILTER_TYPE_TEXT             = 12,  ( string type ) \n"
2057                         "       EMAIL_SEARCH_FILTER_TYPE_SUBJECT          = 13,  ( string type ) \n"
2058                         "       EMAIL_SEARCH_FILTER_TYPE_TO               = 15,  ( string type ) \n"
2059                         "       EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER      = 16,  ( integet type ) \n"
2060                         "       EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER     = 17,  ( integet type ) \n"
2061                         "       EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20,  ( time type ) \n"
2062                         "       EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON     = 21,  ( time type ) \n"
2063                         "       EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE  = 22,  ( time type ) \n"
2064                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED   = 26,  ( integer type ) \n"
2065                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW        = 27,  ( integer type ) \n"
2066                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED    = 28,  ( integer type ) \n"
2067                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD        = 29,  ( integer type ) \n"
2068                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT      = 30,  ( integer type ) \n"
2069                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED     = 32,  ( integer type ) \n"
2070                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT     = 34,  ( integer type ) \n"
2071                         "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN       = 36,  ( integer type ) \n"
2072                         "       EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID       = 43,  ( string type ) \n"
2073                         "       EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY  = 50,  ( integer type ) \n"
2074                         "       EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME  = 60,  ( string type ) \n"
2075                         "       END                                       = 0 \n");
2076
2077                 testapp_print("input search filter type : ");
2078                 if (0 >= scanf("%d", (int*)&search_filter_type))
2079                         testapp_print("Invalid input. ");
2080
2081                 search_filter[search_filter_count].search_filter_type = search_filter_type;
2082
2083                 switch(search_filter_type) {
2084                         case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO       :
2085                         case EMAIL_SEARCH_FILTER_TYPE_UID              :
2086                         case EMAIL_SEARCH_FILTER_TYPE_ALL              :
2087                         case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER      :
2088                         case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER     :
2089                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED   :
2090                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_NEW        :
2091                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED    :
2092                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_OLD        :
2093                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT      :
2094                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED     :
2095                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT     :
2096                         case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN       :
2097                         case EMAIL_SEARCH_FILTER_TYPE_HEADER_PRIORITY  :
2098                                 testapp_print("input search filter key value : ");
2099                                 if (0 >= scanf("%d", &search_key_value_integer))
2100                                         testapp_print("Invalid input. ");
2101                                 search_filter[search_filter_count].search_filter_key_value.integer_type_key_value = search_key_value_integer;
2102                                 break;
2103
2104                         case EMAIL_SEARCH_FILTER_TYPE_BCC              :
2105                         case EMAIL_SEARCH_FILTER_TYPE_BODY             :
2106                         case EMAIL_SEARCH_FILTER_TYPE_CC               :
2107                         case EMAIL_SEARCH_FILTER_TYPE_FROM             :
2108                         case EMAIL_SEARCH_FILTER_TYPE_KEYWORD          :
2109                         case EMAIL_SEARCH_FILTER_TYPE_TEXT             :
2110                         case EMAIL_SEARCH_FILTER_TYPE_SUBJECT          :
2111                         case EMAIL_SEARCH_FILTER_TYPE_TO               :
2112                         case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID       :
2113                         case EMAIL_SEARCH_FILTER_TYPE_ATTACHMENT_NAME  :
2114                                 testapp_print("input search filter key value : ");
2115                                 if (0 >= scanf("%s", search_key_value_string))
2116                                         testapp_print("Invalid input. ");
2117                                 search_filter[search_filter_count].search_filter_key_value.string_type_key_value = strdup(search_key_value_string);
2118                                 break;
2119
2120                         case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
2121                         case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON     :
2122                         case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE  :
2123                                 time(&current_time);
2124                                 /* TODO : write codes for converting string to time */
2125                                 /* search_filter.search_filter_key_value.time_type_key_value = search_key_value_string; */
2126                                 search_filter[search_filter_count].search_filter_key_value.time_type_key_value = current_time;
2127                                 break;
2128                         default :
2129                                 testapp_print("END filter type [%d]", search_filter_type);
2130                                 break;
2131                 }
2132
2133                 if (!search_filter_type)
2134                         break;
2135
2136                 search_filter_count++;
2137         }
2138
2139         if( (err_code = email_search_mail_on_server(account_id, mailbox_id, search_filter, search_filter_count, &handle)) != EMAIL_ERROR_NONE) {
2140                 testapp_print("email_search_mail_on_server failed [%d]", err_code);
2141         }
2142
2143         testapp_print(" >>> testapp_test_search_mail_on_server : END \n");
2144         return TRUE;
2145 }
2146
2147 static gboolean testapp_test_add_mail_to_search_result_box()
2148 {
2149         int                    i = 0;
2150         int                    account_id = 0;
2151         int                    from_eas = 0;
2152         int                    attachment_count = 0;
2153         int                    err = EMAIL_ERROR_NONE;
2154         char                   arg[50] = { 0 , };
2155         char                  *body_file_path = MAIL_TEMP_BODY;
2156         email_mailbox_t         *mailbox_data = NULL;
2157         email_mail_data_t       *test_mail_data = NULL;
2158         email_attachment_data_t *attachment_data = NULL;
2159         email_meeting_request_t *meeting_req = NULL;
2160         FILE                  *body_file = NULL;
2161
2162         testapp_print("\n > Enter account id : ");
2163         if (0 >= scanf("%d", &account_id))
2164                 testapp_print("Invalid input. ");
2165
2166         email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &mailbox_data);
2167
2168         test_mail_data = malloc(sizeof(email_mail_data_t));
2169         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
2170
2171         testapp_print("\n From EAS? [0/1]> ");
2172         if (0 >= scanf("%d", &from_eas))
2173                 testapp_print("Invalid input. ");
2174
2175         test_mail_data->account_id             = account_id;
2176         test_mail_data->save_status            = 1;
2177         test_mail_data->body_download_status   = 1;
2178         test_mail_data->flags_seen_field       = 1;
2179         test_mail_data->file_path_plain        = strdup(body_file_path);
2180         test_mail_data->mailbox_id             = mailbox_data->mailbox_id;
2181         test_mail_data->mailbox_type           = mailbox_data->mailbox_type;
2182         test_mail_data->full_address_from      = strdup("<test1@test.com>");
2183         test_mail_data->full_address_to        = strdup("<test2@test.com>");
2184         test_mail_data->full_address_cc        = strdup("<test3@test.com>");
2185         test_mail_data->full_address_bcc       = strdup("<test4@test.com>");
2186         test_mail_data->subject                = strdup("Into search result mailbox");
2187         test_mail_data->remaining_resend_times = 3;
2188
2189         body_file = fopen(body_file_path, "w");
2190
2191         for(i = 0; i < 500; i++)
2192                 fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
2193         fflush(body_file);
2194         fclose(body_file);
2195
2196         testapp_print(" > Attach file? [0/1] : ");
2197         if (0 >= scanf("%d",&attachment_count))
2198                 testapp_print("Invalid input. ");
2199
2200         if ( attachment_count )  {
2201                 memset(arg, 0x00, 50);
2202                 testapp_print("\n > Enter attachment name : ");
2203                 if (0 >= scanf("%s", arg))
2204                         testapp_print("Invalid input. ");
2205
2206                 attachment_data = malloc(sizeof(email_attachment_data_t));
2207
2208                 attachment_data->attachment_name  = strdup(arg);
2209
2210                 memset(arg, 0x00, 50);
2211                 testapp_print("\n > Enter attachment absolute path : ");
2212                 if (0 >= scanf("%s",arg))
2213                         testapp_print("Invalid input. ");
2214
2215                 attachment_data->attachment_path  = strdup(arg);
2216                 attachment_data->save_status      = 1;
2217                 test_mail_data->attachment_count  = attachment_count;
2218         }
2219
2220         testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
2221         if (0 >= scanf("%d", (int*)&(test_mail_data->meeting_request_status)))
2222                 testapp_print("Invalid input. ");
2223
2224         if ( test_mail_data->meeting_request_status == 1
2225                 || test_mail_data->meeting_request_status == 2 ) {
2226                 time_t current_time;
2227                 /*  dummy data for meeting request */
2228                 meeting_req = malloc(sizeof(email_meeting_request_t));
2229                 memset(meeting_req, 0x00, sizeof(email_meeting_request_t));
2230
2231                 meeting_req->meeting_response     = 1;
2232                 current_time = time(NULL);
2233                 gmtime_r(&current_time, &(meeting_req->start_time));
2234                 gmtime_r(&current_time, &(meeting_req->end_time));
2235                 meeting_req->location = malloc(strlen("Seoul") + 1);
2236                 memset(meeting_req->location, 0x00, strlen("Seoul") + 1);
2237                 strcpy(meeting_req->location, "Seoul");
2238                 strcpy(meeting_req->global_object_id, "abcdef12345");
2239
2240                 meeting_req->time_zone.offset_from_GMT = 9;
2241                 strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
2242                 gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
2243                 meeting_req->time_zone.standard_bias = 3;
2244
2245                 strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
2246                 gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
2247                 meeting_req->time_zone.daylight_bias = 7;
2248
2249         }
2250
2251         if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE)
2252                 testapp_print("email_add_mail failed. [%d]\n", err);
2253         else
2254                 testapp_print("email_add_mail success.\n");
2255
2256         testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
2257
2258         if(attachment_data)
2259                 email_free_attachment_data(&attachment_data, attachment_count);
2260
2261         if(meeting_req)
2262                 email_free_meeting_request(&meeting_req, 1);
2263
2264         email_free_mail_data(&test_mail_data, 1);
2265         email_free_mailbox(&mailbox_data, 1);
2266
2267         return FALSE;
2268 }
2269
2270 static gboolean testapp_test_email_parse_mime_file()
2271 {
2272         int i = 0;
2273         int attachment_count = 0;
2274         int output_attachment_count = 0;
2275         int verify = 0;
2276         int err = EMAIL_ERROR_NONE;
2277         char eml_file_path[255] = {0, };
2278         struct tm *struct_time;
2279
2280         email_mail_data_t *mail_data = NULL;
2281         email_attachment_data_t *mail_attachment_data = NULL;
2282         email_mail_data_t *output_mail_data = NULL;
2283         email_attachment_data_t *output_mail_attachment_data = NULL;
2284
2285         testapp_print("Input eml file path : ");
2286         if (0 >= scanf("%s", eml_file_path))
2287                 testapp_print("Invalid input. ");
2288
2289         if ((err = email_parse_mime_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE) {
2290                 testapp_print("email_parse_mime_file failed : [%d]\n", err);
2291                 return false;   
2292         }
2293        
2294         testapp_print("load success\n");
2295
2296         struct_time = localtime(&(mail_data->date_time));
2297
2298         testapp_print("%4d year",       struct_time->tm_year +1900);
2299         testapp_print("  %2d month(0-11)\n", struct_time->tm_mon  +1   );
2300         testapp_print("  %2d day(1-31)\n", struct_time->tm_mday      );
2301         testapp_print("  %2d wday\n", struct_time->tm_wday);
2302         testapp_print("  %2d hour(0-23)\n", struct_time->tm_hour      );
2303         testapp_print("  %2d minutes(0-59)\n", struct_time->tm_min       );
2304         testapp_print("  %2d second(0-59)\n", struct_time->tm_sec       );
2305         testapp_print("year day %3d\n", struct_time->tm_yday);
2306
2307         testapp_print("Return-Path: %s\n", mail_data->full_address_return);
2308         testapp_print("To: %s\n", mail_data->full_address_to);
2309         testapp_print("Subject: %s\n", mail_data->subject);
2310         testapp_print("Priority: %d\n", mail_data->priority);
2311         testapp_print("From: %s\n", mail_data->full_address_from);
2312         testapp_print("Reply-To: %s\n", mail_data->full_address_reply);
2313         testapp_print("Sender: %s\n", mail_data->email_address_sender);
2314         testapp_print("Message-ID: %s\n", mail_data->message_id);
2315         testapp_print("attachment_count: %d\n", mail_data->attachment_count);
2316         testapp_print("SMIME type : %d\n", mail_data->smime_type);
2317         testapp_print("inline content count : %d\n", mail_data->inline_content_count);
2318         testapp_print("mail_size : %d\n", mail_data->mail_size);
2319         testapp_print("download_body_status : %d\n", mail_data->body_download_status);
2320
2321
2322         for (i = 0;i < attachment_count ; i++) {
2323                 testapp_print("%d attachment\n", i);
2324                 testapp_print("attachment_id: %d\n", mail_attachment_data[i].attachment_id);
2325                 testapp_print("attachment_size: %d\n", mail_attachment_data[i].attachment_size);
2326                 testapp_print("inline_attachment_status: %d\n", mail_attachment_data[i].inline_content_status);
2327                 testapp_print("attachment_name: %s\n", mail_attachment_data[i].attachment_name);
2328                 testapp_print("attachment_path: %s\n", mail_attachment_data[i].attachment_path);
2329                 testapp_print("attachment_save_status: %d\n", mail_attachment_data[i].save_status);
2330                 testapp_print("content_id: %s\n", mail_attachment_data[i].content_id);
2331                 testapp_print("mailbox_id: %d\n", mail_attachment_data[i].mailbox_id);
2332         }
2333
2334         testapp_print("Success : Open eml file\n");
2335
2336         if (mail_data->smime_type != EMAIL_SMIME_NONE) {
2337                 if (mail_data->smime_type == EMAIL_SMIME_SIGNED || mail_data->smime_type == EMAIL_PGP_SIGNED) {
2338                         if (!email_verify_signature_ex(mail_data, mail_attachment_data, attachment_count, &verify)) 
2339                                 testapp_print("email_verify_signature_ex failed\n");
2340                 } else {
2341                         if ((err = email_get_decrypt_message_ex(mail_data, 
2342                                                                                                         mail_attachment_data, 
2343                                                                                                         attachment_count, 
2344                                                                                                         &output_mail_data, 
2345                                                                                                         &output_mail_attachment_data, 
2346                                                                                                         &output_attachment_count,
2347                                                                                                         &verify)) != EMAIL_ERROR_NONE)
2348                                 testapp_print("email_get_decrypt_message_ex failed\n");
2349                 }
2350                 
2351                 testapp_print("verify : [%d]\n", verify);
2352         }       
2353         
2354         if ((err = email_delete_parsed_data(mail_data)) != EMAIL_ERROR_NONE) {
2355                 testapp_print("email_delete_eml_data failed : [%d]\n", err);
2356                 return false;
2357         }
2358
2359         testapp_print("Success : email_delete_eml_data\n");
2360
2361         if (mail_data)
2362                 email_free_mail_data(&mail_data, 1);
2363         
2364         testapp_print("Success : email_free_mail_data\n");
2365
2366         if (mail_attachment_data)
2367                 email_free_attachment_data(&mail_attachment_data, attachment_count);
2368
2369         testapp_print("Success : email_free_attachment_data\n");
2370
2371         return true;
2372
2373 }
2374
2375 static gboolean testapp_test_email_write_mime_file()
2376 {
2377         int err = EMAIL_ERROR_NONE;
2378         int mail_id = 0;
2379         int attachment_count = 0;
2380         char *file_path = NULL;
2381         email_mail_data_t *mail_data = NULL;
2382         email_attachment_data_t *mail_attachment_data = NULL;
2383
2384
2385         file_path = malloc(512);
2386         memset(file_path, 0x00, 512);
2387
2388         testapp_print("Input mail id : ");
2389         if (0 >= scanf("%d", &mail_id))
2390                 testapp_print("Invalid input. ");
2391
2392         err = email_get_mail_data(mail_id, &mail_data);
2393         if (err != EMAIL_ERROR_NONE || mail_data == NULL) {
2394                 testapp_print("email_get_mail_data failed : [%d]\n", err);
2395                 return false;
2396         }
2397
2398         err = email_get_attachment_data_list(mail_id, &mail_attachment_data, &attachment_count);
2399         if (err != EMAIL_ERROR_NONE) {
2400                 testapp_print("email_get_attachment_data_list failed : [%d]\n", err);
2401                 return false;
2402         }
2403
2404         snprintf(file_path, 512, "/opt/usr/data/email/.email_data/tmp/%d_%8d.eml", mail_id, (int)time(NULL));
2405
2406         err = email_write_mime_file(mail_data, mail_attachment_data, attachment_count, &file_path);
2407         if (err != EMAIL_ERROR_NONE) {
2408                 testapp_print("email_write_mime_file failed : [%d]\n", err);
2409                 return false;
2410         }
2411
2412         testapp_print("file path : [%s]\n", file_path);
2413
2414         if (mail_data)
2415                 email_free_mail_data(&mail_data, 1);
2416         
2417         if (mail_attachment_data)
2418                 email_free_attachment_data(&mail_attachment_data, attachment_count);
2419
2420         if (file_path)
2421                 free(file_path);
2422
2423         return true;
2424 }
2425
2426 static gboolean testapp_test_smime_verify_signature()
2427 {
2428         int mail_id = 0;
2429         int verify = 0;
2430         int err = EMAIL_ERROR_NONE;
2431
2432         testapp_print("input mail_id :");
2433         if (0 >= scanf("%d", &mail_id))
2434                 testapp_print("Invalid input. ");
2435         
2436         err = email_verify_signature(mail_id, &verify);
2437         if (err != EMAIL_ERROR_NONE) {
2438                 testapp_print("Failed Verify\n");
2439                 return false;
2440         }
2441
2442         testapp_print("verify value : [%d]\n", verify); 
2443         return true;
2444 }
2445
2446 static gboolean testapp_test_email_add_mail_with_multiple_recipient()
2447 {
2448         int                    i = 0;
2449         int                    account_id = 0;
2450         int                    err = EMAIL_ERROR_NONE;
2451 //      int                    smime_type = 0;
2452         int                    recipient_addresses_count = 0;
2453         char                  *recipient_addresses = NULL;
2454         char                   recipient_address[234] = { 0, };
2455         char                   from_address[300] = { 0 , };
2456         const char            *body_file_path = MAIL_TEMP_BODY;
2457         email_account_t       *account_data = NULL;
2458         email_mailbox_t       *mailbox_data = NULL;
2459         email_mail_data_t     *test_mail_data = NULL;
2460         FILE                  *body_file;
2461
2462         testapp_print("\n > Enter account id : ");
2463         if (0 >= scanf("%d", &account_id))
2464                 testapp_print("Invalid input. ");
2465
2466         testapp_print("\n > Enter recipient address count : ");
2467         if (0 >= scanf("%d", &recipient_addresses_count))
2468                 testapp_print("Invalid input. ");
2469
2470         if(recipient_addresses_count < 1)
2471                 return TRUE;
2472
2473         recipient_addresses = malloc(sizeof(char) * 234 * recipient_addresses_count);
2474
2475         for (i = 0; i < recipient_addresses_count; i++) {
2476                 snprintf(recipient_address, 234, "\"mailtest%05d\" <mailtest%05d@a1234567890b1234567890.com>; ", i, i);
2477                 strcat(recipient_addresses, recipient_address);
2478         }
2479
2480         email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data);
2481
2482         email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_data);
2483
2484         test_mail_data = malloc(sizeof(email_mail_data_t));
2485         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
2486
2487         SNPRINTF(from_address, 300, "<%s>", account_data->user_email_address);
2488
2489         test_mail_data->account_id             = account_id;
2490         test_mail_data->save_status            = EMAIL_MAIL_STATUS_SEND_DELAYED;
2491         test_mail_data->body_download_status   = 1;
2492         test_mail_data->flags_seen_field       = 1;
2493         test_mail_data->file_path_plain        = strdup(body_file_path);
2494         test_mail_data->mailbox_id             = mailbox_data->mailbox_id;
2495         test_mail_data->mailbox_type           = mailbox_data->mailbox_type;
2496         test_mail_data->full_address_from      = strdup(from_address);
2497         test_mail_data->full_address_to        = recipient_addresses;
2498         test_mail_data->subject                = strdup("Read receipt request from TIZEN");
2499         test_mail_data->remaining_resend_times = 3;
2500         test_mail_data->report_status          = EMAIL_MAIL_REQUEST_DSN | EMAIL_MAIL_REQUEST_MDN;
2501         test_mail_data->smime_type             = 0;
2502
2503         body_file = fopen(body_file_path, "w");
2504
2505         testapp_print("\n body_file [%p]\n", body_file);
2506
2507         if(body_file == NULL) {
2508                 testapp_print("\n fopen [%s]failed\n", body_file_path);
2509                 return FALSE;
2510         }
2511
2512         for(i = 0; i < 100; i++)
2513                 fprintf(body_file, "Mail sending Test. [%d]\n", i);
2514
2515         fflush(body_file);
2516         fclose(body_file);
2517
2518
2519         if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE)
2520                 testapp_print("email_add_mail failed. [%d]\n", err);
2521         else
2522                 testapp_print("email_add_mail success.\n");
2523
2524         testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
2525
2526         email_free_mail_data(&test_mail_data, 1);
2527         email_free_mailbox(&mailbox_data, 1);
2528         email_free_account(&account_data, 1);
2529
2530         return FALSE;
2531 }
2532
2533 static gboolean testapp_test_send_mails_every_x_minutes()
2534 {
2535         int                    added_mail_id = 0;
2536         int                    err = EMAIL_ERROR_NONE;
2537         int                    handle = 0;
2538         time_t                 time_to_send;
2539         int                    i = 0;
2540         int                    j = 0;
2541         int                    account_id = 0;
2542         int                    send_interval_in_minutes = 0;
2543         int                    number_of_mails = 0;
2544         char                   recipient_address[300] = { 0 , };
2545         char                   from_address[300] = { 0 , };
2546         char                   subject_form[1024] = { 0 , };
2547         const char            *body_file_path = MAIL_TEMP_BODY;
2548         struct tm             *time_to_send_tm;
2549         email_account_t       *account_data = NULL;
2550         email_mailbox_t       *mailbox_data = NULL;
2551         email_mail_data_t     *test_mail_data = NULL;
2552         FILE                  *body_file;
2553
2554         testapp_print("\n > Enter account id : ");
2555         if (0 >= scanf("%d", &account_id))
2556                 testapp_print("Invalid input. ");
2557
2558         testapp_print("\n > Enter recipient address : ");
2559         if (0 >= scanf("%s", recipient_address))
2560                 testapp_print("Invalid input. ");
2561
2562         testapp_print("\n > Enter number of mails: ");
2563         if (0 >= scanf("%d", &number_of_mails))
2564                 testapp_print("Invalid input. ");
2565
2566         testapp_print("\n > Enter send interval in minutes: ");
2567         if (0 >= scanf("%d", &send_interval_in_minutes))
2568                 testapp_print("Invalid input. ");
2569
2570         email_get_account(account_id, GET_FULL_DATA_WITHOUT_PASSWORD, &account_data);
2571
2572         email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox_data);
2573
2574         test_mail_data = malloc(sizeof(email_mail_data_t));
2575         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
2576
2577         SNPRINTF(from_address, 300, "<%s>", account_data->user_email_address);
2578
2579         test_mail_data->account_id             = account_id;
2580         test_mail_data->save_status            = EMAIL_MAIL_STATUS_SEND_DELAYED;
2581         test_mail_data->body_download_status   = 1;
2582         test_mail_data->flags_seen_field       = 1;
2583         test_mail_data->file_path_plain        = strdup(body_file_path);
2584         test_mail_data->mailbox_id             = mailbox_data->mailbox_id;
2585         test_mail_data->mailbox_type           = mailbox_data->mailbox_type;
2586         test_mail_data->full_address_from      = strdup(from_address);
2587         test_mail_data->full_address_to        = strdup(recipient_address);
2588         test_mail_data->remaining_resend_times = 3;
2589         test_mail_data->report_status          = EMAIL_MAIL_REPORT_NONE;
2590
2591
2592         for (i = 0; i < number_of_mails; i++) {
2593                 if (test_mail_data->subject)
2594                         free(test_mail_data->subject);
2595
2596                 time(&time_to_send);
2597                 time_to_send += (60 * send_interval_in_minutes) * (i + 1);
2598                 time_to_send_tm = localtime(&time_to_send);
2599
2600                 strftime(subject_form, 1024, "[%H:%M] TEST.", time_to_send_tm);
2601                 test_mail_data->subject = strdup(subject_form);
2602
2603                 body_file = fopen(body_file_path, "w");
2604
2605                 testapp_print("\n body_file [%p]\n", body_file);
2606
2607                 if(body_file == NULL) {
2608                         testapp_print("\n fopen [%s]failed\n", body_file_path);
2609                         return FALSE;
2610                 }
2611
2612                 for(j = 0; j < 100; j++)
2613                         fprintf(body_file, "Mail sending Test. [%d]\n", j);
2614
2615                 fflush(body_file);
2616                 fclose(body_file);
2617
2618                 if((err = email_add_mail(test_mail_data, NULL, 0, NULL, 0)) != EMAIL_ERROR_NONE) {
2619                         testapp_print("email_add_mail failed. [%d]\n", err);
2620                         added_mail_id = 0;
2621                 }
2622                 else {
2623                         testapp_print("email_add_mail success.\n");
2624                         added_mail_id = test_mail_data->mail_id;
2625                 }
2626
2627                 testapp_print("saved mail id = [%d]\n", added_mail_id);
2628
2629                 if(added_mail_id) {
2630                         testapp_print("Calling email_schedule_sending_mail...\n");
2631
2632                         if( email_schedule_sending_mail(added_mail_id, time_to_send) < 0) {
2633                                 testapp_print("email_schedule_sending_mail failed[%d]\n", err);
2634                         }
2635                         else  {
2636                                 testapp_print("Start sending. handle[%d]\n", handle);
2637                         }
2638                 }
2639         }
2640
2641         email_free_mail_data(&test_mail_data, 1);
2642         email_free_mailbox(&mailbox_data, 1);
2643         email_free_account(&account_data, 1);
2644
2645         return TRUE;
2646 }
2647
2648 /* internal functions */
2649 static gboolean testapp_test_interpret_command (int menu_number)
2650 {
2651         gboolean go_to_loop = TRUE;
2652         
2653         switch (menu_number) {
2654                 case 1:
2655                         testapp_test_get_mails();
2656                         break;
2657                 case 2:
2658                         testapp_test_mail_send(NULL);
2659                         break;
2660                 case 3:
2661                         testapp_test_get_mail_list_ex();
2662                         break;
2663                 case 4:
2664                         testapp_test_add_attachment();
2665                         break;                  
2666                 case 5:
2667                         testapp_test_set_deleted_flag();
2668                         break;
2669                 case 6:
2670                         testapp_test_expunge_mails_deleted_flagged();
2671                         break;
2672                 case 7:
2673                         testapp_test_send_read_receipt();
2674                         break;
2675                 case 8:
2676                         testapp_test_delete_attachment();
2677                         break;
2678                 case 9:
2679                         testapp_test_count();
2680                         break;
2681                 case 10:
2682                         testapp_test_move_mails_to_mailbox_of_another_account();
2683                         break;
2684                 case 11:
2685                         testapp_test_send_mail_with_downloading_attachment_of_original_mail();
2686                         break;
2687                 case 12:
2688                         testapp_test_get_mail_data();
2689                         break;
2690                 case 13:
2691                         testapp_test_schedule_sending_mail();
2692                         break;
2693                 case 14:
2694                         testapp_test_delete();
2695                         break;
2696                 case 15:
2697                         testapp_test_update_mail_attribute();
2698                         break;
2699                 case 16:
2700                         testapp_test_download_body();
2701                         break;
2702                 case 17:
2703                         testapp_test_download_attachment();
2704                         break;          
2705                 case 18:
2706                         testapp_test_get_attachment_data_list();
2707                         break;
2708                 case 19:
2709                         testapp_test_get_meeting_request();
2710                         break;
2711                 case 20:
2712                         testapp_test_delete_all();
2713                         break;
2714                 case 21:
2715                         testapp_test_move();
2716                         break;
2717                 case 23:
2718                         testapp_test_retry_send();
2719                         break;
2720                 case 24:
2721                         testapp_test_get_attachment_data();
2722                         break;
2723                 case 27:
2724                         testapp_test_move_all_mails_to_mailbox();
2725                         break;
2726                 case 38:
2727                         testapp_test_get_totaldiskusage();
2728                         break;
2729                 case 40:
2730                         testapp_test_address_format_check_test();
2731                         break;
2732                 case 41:
2733                         testapp_test_get_max_mail_count();
2734                         break;
2735                 case 42:
2736                         testapp_test_db_test();
2737                         break;
2738                 case 43:
2739                         testapp_test_send_cancel();
2740                         break;
2741                 case 44:
2742                         testapp_test_cancel_download_body();
2743                         break;
2744                 case 46:
2745                          testapp_test_get_mail_list_for_thread_view();
2746                         break;
2747                 case 48:
2748                         testapp_test_test_get_thread_information();
2749                         break;
2750                 case 51:
2751                         testapp_test_get_mail_list();
2752                         break;
2753                 case 52:
2754                         testapp_test_get_address_info_list();
2755                         break;
2756                 case 55:
2757                         testapp_test_set_flags_field();
2758                         break;
2759                 case 56:
2760                         testapp_test_add_mail(NULL);
2761                         break;
2762                 case 57:
2763                         testapp_test_update_mail();
2764                         break;
2765                 case 58:
2766                         testapp_test_search_mail_on_server();
2767                         break;
2768                 case 59:
2769                         testapp_test_add_mail_to_search_result_box();
2770                         break;
2771                 case 60:
2772                         testapp_test_email_parse_mime_file();
2773                         break;
2774                 case 61:
2775                         testapp_test_email_write_mime_file();
2776                         break;
2777                 case 62:
2778                         testapp_test_smime_verify_signature();
2779                         break;
2780                 case 63:
2781                         testapp_test_email_add_mail_with_multiple_recipient();
2782                         break;
2783                 case 64:
2784                         testapp_test_send_mails_every_x_minutes();
2785                         break;
2786                 case 0:
2787                         go_to_loop = FALSE;
2788                         break;
2789                 default:
2790                         break;
2791         }
2792
2793         return go_to_loop;
2794 }
2795
2796 void testapp_mail_main()
2797 {
2798         gboolean go_to_loop = TRUE;
2799         int menu_number = 0;
2800         
2801         while (go_to_loop) {
2802                 testapp_show_menu(EMAIL_MAIL_MENU);
2803                 testapp_show_prompt(EMAIL_MAIL_MENU);
2804                         
2805                 if (0 >= scanf("%d", &menu_number))
2806                         testapp_print("Invalid input");
2807
2808                 go_to_loop = testapp_test_interpret_command (menu_number);
2809         }
2810 }
2811