2.0_alpha release commit
[framework/messaging/email-service.git] / utilities / test-application / testapp-mail.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21
22
23
24 /* common header */
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <sys/stat.h>
29
30 /* open header */
31 #include <glib.h>
32 #include <time.h>
33
34 #include "email-api-account.h"
35 #include "email-api-network.h"
36 #include "email-api-mail.h"
37 #include "email-api-mailbox.h"
38 #include "email-api-etc.h"
39
40 /* internal header */
41 #include "testapp-utility.h"
42 #include "testapp-mail.h"
43 #include "email-core-utils.h"
44 #include "email-core-mime.h"
45
46 #define MAIL_TEMP_BODY "/tmp/mail.txt"
47
48 /*
49 static void testapp_test_print_sorting_menu()
50 {
51         testapp_print("   EMAIL_SORT_DATETIME_HIGH = 0\n");
52         testapp_print("   EMAIL_SORT_DATETIME_LOW = 1\n");      
53         testapp_print("   EMAIL_SORT_SENDER_HIGH = 2\n");
54         testapp_print("   EMAIL_SORT_SENDER_LOW = 3\n");   
55         testapp_print("   EMAIL_SORT_RCPT_HIGH = 4\n");
56         testapp_print("   EMAIL_SORT_RCPT_LOW = 5\n");    
57         testapp_print("   EMAIL_SORT_SUBJECT_HIGH = 6\n");
58         testapp_print("   EMAIL_SORT_SUBJECT_LOW = 7\n");   
59         testapp_print("   EMAIL_SORT_PRIORITY_HIGH = 8\n");
60         testapp_print("   EMAIL_SORT_PRIORITY_LOW = 9\n");   
61         testapp_print("   EMAIL_SORT_ATTACHMENT_HIGH = 10\n");
62         testapp_print("   EMAIL_SORT_ATTACHMENT_LOW = 11\n");   
63         testapp_print("   EMAIL_SORT_FAVORITE_HIGH = 12\n");
64         testapp_print("   EMAIL_SORT_FAVORITE_LOW = 13\n");   
65 }
66
67 static void testapp_test_print_mail_list_item(email_mail_list_item_t *mail_list_item, int count)
68 {
69         int i;
70         
71         testapp_print("\n>>>>> Print mail list items: count[%d]\n", count);
72         for (i=0; i< count; i++) {
73                 testapp_print("\n[%d]\n", i);
74                 testapp_print(" >>> Mailbox Name [ %s ] \n", mail_list_item[i].mailbox_name);
75                 testapp_print(" >>> Mail ID [ %d ] \n", mail_list_item[i].mail_id);
76                 testapp_print(" >>> Account ID [ %d ] \n", mail_list_item[i].account_id);
77                 if (  mail_list_item[i].from!= NULL ) {
78                         testapp_print(" >>> From [ %s ] \n", mail_list_item[i].from);
79                 }
80                 if (  mail_list_item[i].from_email_address != NULL ) {
81                         testapp_print(" >>> from_email_address [ %s ] \n", mail_list_item[i].from_email_address);
82                 }
83                 if (  mail_list_item[i].recipients!= NULL ) {
84                         testapp_print(" >>> recipients [ %s ] \n", mail_list_item[i].recipients);
85                 }
86                 if (  mail_list_item[i].subject != NULL ) {
87                         testapp_print(" >>> subject [ %s ] \n", mail_list_item[i].subject);
88                 }
89                 testapp_print(" >>> text_download_yn [ %d ] \n", mail_list_item[i].is_text_downloaded);
90                 testapp_print(" >>> date_time [ %d ] \n", mail_list_item[i].date_time);
91                 testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list_item[i].flags_seen_field);
92                 testapp_print(" >>> priority [ %d ] \n", mail_list_item[i].priority);
93                 testapp_print(" >>> save_status [ %d ] \n", mail_list_item[i].save_status);
94                 testapp_print(" >>> lock [ %d ] \n", mail_list_item[i].is_locked);
95                 testapp_print(" >>> is_report_mail [ %d ] \n", mail_list_item[i].is_report_mail);
96                 testapp_print(" >>> recipients_count [ %d ] \n", mail_list_item[i].recipients_count);
97                 testapp_print(" >>> has_attachment [ %d ] \n", mail_list_item[i].has_attachment);
98                 testapp_print(" >>> has_drm_attachment [ %d ] \n", mail_list_item[i].has_drm_attachment);
99
100                 if (  mail_list_item[i].previewBodyText != NULL ) {
101                         testapp_print(" >>> previewBodyText [ %s ] \n", mail_list_item[i].previewBodyText);
102                 }
103
104                 testapp_print(" >>> thread_id [ %d ] \n", mail_list_item[i].thread_id);
105                 testapp_print(" >>> thread_item_count [ %d ] \n", mail_list_item[i].thread_item_count);
106         }
107 }
108 */
109
110 static gboolean testapp_test_add_mail (int *result_mail_id)
111 {
112         int                    result_from_scanf = 0;
113         int                    i = 0;
114         int                    account_id = 0;
115         int                    mailbox_id = 0;
116         int                    from_eas = 0;
117         int                    attachment_count = 0;
118         int                    err = EMAIL_ERROR_NONE;
119         int                    smime_type = 0;
120         char                   arg[50] = { 0 , };
121         const char            *body_file_path = MAIL_TEMP_BODY;
122         email_mailbox_t         *mailbox_data = NULL;
123         email_mail_data_t       *test_mail_data = NULL;
124         email_attachment_data_t *attachment_data = NULL;
125         email_meeting_request_t *meeting_req = NULL;
126         FILE                  *body_file;
127  
128         testapp_print("\n > Enter account id : ");
129         result_from_scanf = scanf("%d", &account_id);
130
131         
132         memset(arg, 0x00, 50);
133         testapp_print("\n > Enter mailbox id : ");
134         result_from_scanf = scanf("%d", &mailbox_id);
135
136         email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox_data);
137
138         test_mail_data = malloc(sizeof(email_mail_data_t));
139         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
140         
141         testapp_print("\n Sync server? [0/1]> ");
142         result_from_scanf = scanf("%d", &from_eas);
143
144         test_mail_data->account_id           = account_id;
145         test_mail_data->save_status          = 1;
146         test_mail_data->body_download_status = 1;
147         test_mail_data->flags_seen_field     = 1;
148         test_mail_data->file_path_plain      = strdup(body_file_path);
149         test_mail_data->mailbox_id           = mailbox_id;
150         test_mail_data->mailbox_type         = mailbox_data->mailbox_type;
151         test_mail_data->full_address_from    = strdup("<test1@test.com>");
152         test_mail_data->full_address_to      = strdup("<test2@test.com>");
153         test_mail_data->full_address_cc      = strdup("<test3@test.com>");
154         test_mail_data->full_address_bcc     = strdup("<test4@test.com>");
155         test_mail_data->subject              = strdup("Meeting request mail");
156
157         body_file = fopen(body_file_path, "w");
158
159         testapp_print("\n body_file [%p]\n", body_file);
160
161         if(body_file == NULL) {
162                 testapp_print("\n fopen [%s]failed\n", body_file_path);
163                 return FALSE;
164         }
165 /*      
166         for(i = 0; i < 500; i++)
167                 fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
168 */
169         fprintf(body_file, "Hello world");
170         fflush(body_file);
171         fclose(body_file);
172
173         testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt] : ");
174         result_from_scanf = scanf("%d", &smime_type);
175         test_mail_data->smime_type = smime_type;
176         
177         testapp_print(" > How many file attachment? [>=0] : ");
178         result_from_scanf = scanf("%d",&attachment_count);
179         
180         test_mail_data->attachment_count  = attachment_count;
181         if ( attachment_count > 0 )
182                 attachment_data = calloc(attachment_count, sizeof(email_attachment_data_t));
183
184
185         for ( i = 0; i < attachment_count ; i++ ) {
186                 memset(arg, 0x00, 50);
187                 testapp_print("\n > Enter attachment name : ");
188                 result_from_scanf = scanf("%s", arg);
189
190                 attachment_data[i].attachment_name  = strdup(arg);
191                 
192                 memset(arg, 0x00, 50);
193                 testapp_print("\n > Enter attachment absolute path : ");
194                 result_from_scanf = scanf("%s",arg);
195                 
196                 attachment_data[i].attachment_path  = strdup(arg);
197                 attachment_data[i].save_status      = 1;
198                 attachment_data[i].mailbox_id       = test_mail_data->mailbox_id;
199         }
200         
201         testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
202         result_from_scanf = scanf("%d", &(test_mail_data->meeting_request_status));
203         
204         if ( test_mail_data->meeting_request_status == 1 
205                 || test_mail_data->meeting_request_status == 2 ) {
206                 time_t current_time;
207                 /*  dummy data for meeting request */
208                 meeting_req = malloc(sizeof(email_meeting_request_t));
209                 memset(meeting_req, 0x00, sizeof(email_meeting_request_t));
210                 
211                 meeting_req->meeting_response     = 1;
212                 current_time = time(NULL);
213                 gmtime_r(&current_time, &(meeting_req->start_time));
214                 gmtime_r(&current_time, &(meeting_req->end_time));
215                 meeting_req->location = strdup("Seoul");
216                 meeting_req->global_object_id = strdup("abcdef12345");
217
218                 meeting_req->time_zone.offset_from_GMT = 9;
219                 strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
220                 gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
221                 meeting_req->time_zone.standard_bias = 3;
222                 
223                 strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
224                 gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
225                 meeting_req->time_zone.daylight_bias = 7;
226
227         }
228         
229         if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE)
230                 testapp_print("email_add_mail failed. [%d]\n", err);
231         else
232                 testapp_print("email_add_mail success.\n");
233
234         testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
235
236         if(result_mail_id)
237                 *result_mail_id = test_mail_data->mail_id;
238
239         if(attachment_data)
240                 email_free_attachment_data(&attachment_data, attachment_count);
241                 
242         if(meeting_req)
243                 email_free_meeting_request(&meeting_req, 1);
244                 
245         email_free_mail_data(&test_mail_data, 1);
246         email_free_mailbox(&mailbox_data, 1);
247
248         return FALSE;
249 }
250
251 static gboolean testapp_test_update_mail()
252 {
253         int                    result_from_scanf = 0;
254         int                    mail_id = 0;
255         int                    err = EMAIL_ERROR_NONE;
256         int                    test_attachment_data_count = 0;
257         char                   arg[50];
258         email_mail_data_t       *test_mail_data = NULL;
259         email_attachment_data_t *test_attachment_data_list = NULL;
260         email_meeting_request_t *meeting_req = NULL;
261         
262         testapp_print("\n > Enter mail id : ");
263         result_from_scanf = scanf("%d", &mail_id);
264
265         email_get_mail_data(mail_id, &test_mail_data);
266
267         testapp_print("\n > Enter Subject: ");
268         result_from_scanf = scanf("%s", arg);
269
270         test_mail_data->subject= strdup(arg);
271
272         if (test_mail_data->attachment_count > 0) {
273                 if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) {
274                         testapp_print("email_get_meeting_request() failed [%d]\n", err);
275                         return FALSE;
276                 }
277         }       
278
279         if ( test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST 
280                 || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE 
281                 || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
282                 
283                 if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMAIL_ERROR_NONE ) {
284                         testapp_print("email_get_meeting_request() failed [%d]\n", err);
285                         return FALSE;
286                 }
287         
288                 testapp_print("\n > Enter meeting response: ");
289                 result_from_scanf = scanf("%d", (int*)&(meeting_req->meeting_response));
290         }
291         
292         if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMAIL_ERROR_NONE) 
293                         testapp_print("email_update_mail failed.[%d]\n", err);
294                 else
295                         testapp_print("email_update_mail success\n");
296                 
297         if(test_mail_data)
298                 email_free_mail_data(&test_mail_data, 1);
299                 
300         if(test_attachment_data_list) 
301                 email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count);
302                 
303         if(meeting_req)
304                 email_free_meeting_request(&meeting_req, 1);
305
306         return TRUE;
307 }
308
309 static gboolean testapp_test_get_mails()
310 {
311         testapp_print("\n >>> testapp_test_get_mails : Entered \n");
312         email_mail_data_t *mails = NULL, **mails_pointer = NULL;
313         int mailbox_id = 0;
314         int count = 0, i = 0;
315         int account_id = 0;
316         int start_index =0;
317         int limit_count = 0;
318         int sorting = 0;
319         int err_code = EMAIL_ERROR_NONE;
320         int to_get_count = 0;
321         int is_for_thread_view = 0;
322         int list_type;
323         int result_from_scanf = 0;
324         struct tm *temp_time_info;
325
326         testapp_print("\n > Enter Account_id (0 = all accounts) : ");
327         result_from_scanf = scanf("%d",&account_id);
328
329         testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :");
330         result_from_scanf = scanf("%d", &mailbox_id);
331
332         testapp_print("\n > Enter Sorting : ");
333         result_from_scanf = scanf("%d",&sorting);
334
335         testapp_print("\n > Enter Start index (starting at 0): ");
336         result_from_scanf = scanf("%d",&start_index);
337
338         testapp_print("\n > Enter max_count : ");
339         result_from_scanf = scanf("%d",&limit_count);
340
341         testapp_print("\n > For thread view : ");
342         result_from_scanf = scanf("%d",&is_for_thread_view);
343
344         testapp_print("\n > Mail count only (0:list 1:count): ");
345         result_from_scanf = scanf("%d",&to_get_count);
346
347         if(to_get_count)
348                 mails_pointer = NULL;
349         else
350                 mails_pointer = &mails;
351
352         if(is_for_thread_view == -2) {
353                 list_type = EMAIL_LIST_TYPE_LOCAL;
354         }
355         else if(is_for_thread_view == -1)
356                 list_type = EMAIL_LIST_TYPE_THREAD;
357         else
358                 list_type = EMAIL_LIST_TYPE_NORMAL;
359
360         /* Get mail list */
361         if(mailbox_id == 0) {
362                 testapp_print("Calling email_get_mail_list for all mailbox.\n");
363                 err_code = email_get_mails(account_id, 0, list_type, start_index, limit_count, sorting, mails_pointer, &count);
364                 if ( err_code < 0)
365                         testapp_print("email_get_mails failed - err[%d]\n", err_code);
366         }
367         else {
368                 testapp_print("Calling email_get_mail_list for %d mailbox_id.\n", mailbox_id);
369                 err_code = email_get_mails(account_id, mailbox_id, list_type, start_index, limit_count, sorting,  mails_pointer, &count);
370                 if ( err_code < 0)
371                         testapp_print("email_get_mails failed - err[%d]\n", err_code);
372         }
373         testapp_print("email_get_mails >>>>>>count - %d\n",count);
374
375         if (mails) {
376                 for (i=0; i< count; i++) {
377                         testapp_print("\n[%d]\n", i);
378                         testapp_print(" >>> mailbox_id [ %d ] \n", mails[i].mailbox_id);
379                         testapp_print(" >>> mail_id [ %d ] \n", mails[i].mail_id);
380                         testapp_print(" >>> account_id [ %d ] \n", mails[i].account_id);
381                         if (  mails[i].full_address_from != NULL )
382                                 testapp_print(" >>> full_address_from [ %s ] \n", mails[i].full_address_from);
383                         if (  mails[i].full_address_to != NULL )
384                                 testapp_print(" >>> recipients [ %s ] \n", mails[i].full_address_to);
385                         if (  mails[i].subject != NULL )
386                                 testapp_print(" >>> subject [ %s ] \n", mails[i].subject);
387                         testapp_print(" >>> body_download_status [ %d ] \n", mails[i].body_download_status);
388                         temp_time_info = localtime(&mails[i].date_time);
389                         testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
390                                                                         temp_time_info->tm_year + 1900,
391                                                                         temp_time_info->tm_mon+1,
392                                                                         temp_time_info->tm_mday,
393                                                                         temp_time_info->tm_hour,
394                                                                         temp_time_info->tm_min,
395                                                                         temp_time_info->tm_sec);
396                         testapp_print(" >>> flags_seen_field [ %d ] \n", mails[i].flags_seen_field);
397                         testapp_print(" >>> priority [ %d ] \n", mails[i].priority);
398                         testapp_print(" >>> save_status [ %d ] \n", mails[i].save_status);
399                         testapp_print(" >>> lock_status [ %d ] \n", mails[i].lock_status);
400                         testapp_print(" >>> attachment_count [ %d ] \n", mails[i].attachment_count);
401                         if (  mails[i].preview_text != NULL )
402                                 testapp_print(" >>> previewBodyText [ %s ] \n", mails[i].preview_text);
403                 }
404                 free(mails);
405         }
406
407         testapp_print(" >>> testapp_test_get_mails : End \n");
408         return 0;
409 }
410
411 #define TEMP_ARGUMENT_SIZE 4096
412
413 static gboolean testapp_test_mail_send (int *result_mail_id)
414 {
415         int                    added_mail_id = 0;
416         int                    err = EMAIL_ERROR_NONE;
417         unsigned               handle = 0;
418         email_option_t           option = { 0 };
419         email_mailbox_t          mailbox_data = { 0 };
420         email_mail_data_t       *result_mail_data = NULL;
421
422         testapp_test_add_mail(&added_mail_id);
423         
424         if(result_mail_id) {
425                 email_get_mail_data(added_mail_id, &result_mail_data);
426
427                 memset(&mailbox_data, 0x00, sizeof(email_mailbox_t));
428                 mailbox_data.account_id   = result_mail_data->account_id;
429                 mailbox_data.mailbox_id   = result_mail_data->mailbox_id;
430                 option.keep_local_copy    = 1;
431
432                 testapp_print("Calling email_send_mail...\n");
433
434                 if( email_send_mail(added_mail_id, &option, &handle) < 0) {
435                         testapp_print("Sending failed[%d]\n", err);
436                 }
437                 else  {
438                         testapp_print("Start sending. handle[%d]\n", handle);
439                 }
440
441                 email_free_mail_data(&result_mail_data, 1);
442         }
443
444         if(result_mail_id)
445                 *result_mail_id = added_mail_id;
446
447         return FALSE;
448 }
449
450 static gboolean testapp_test_get_mail_list()
451 {
452         email_list_filter_t *filter_list = NULL;
453         email_list_sorting_rule_t *sorting_rule_list = NULL;
454         email_mail_list_item_t *result_mail_list = NULL;
455         int result_mail_count = 0;
456         int err = EMAIL_ERROR_NONE;
457         int i = 0;
458
459         filter_list = malloc(sizeof(email_list_filter_t) * 9);
460         memset(filter_list, 0 , sizeof(email_list_filter_t) * 9);
461
462         filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
463         filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
464         filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
465         filter_list[0].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
466         filter_list[0].list_filter_item.rule.case_sensitivity              = false;
467
468         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
469         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
470
471         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
472         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_TO;
473         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
474         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
475         filter_list[2].list_filter_item.rule.case_sensitivity              = false;
476
477         filter_list[3].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
478         filter_list[3].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
479
480         filter_list[4].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
481         filter_list[4].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_CC;
482         filter_list[4].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
483         filter_list[4].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
484         filter_list[4].list_filter_item.rule.case_sensitivity              = false;
485
486         filter_list[5].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
487         filter_list[5].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
488
489         filter_list[6].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
490         filter_list[6].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_BCC;
491         filter_list[6].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
492         filter_list[6].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
493         filter_list[6].list_filter_item.rule.case_sensitivity              = false;
494
495         filter_list[7].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
496         filter_list[7].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
497
498         filter_list[8].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
499         filter_list[8].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_FROM;
500         filter_list[8].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
501         filter_list[8].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
502         filter_list[8].list_filter_item.rule.case_sensitivity              = false;
503
504         /*
505         filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
506         filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
507         filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
508         filter_list[0].list_filter_item.rule.key_value.integer_type_value  = 1;
509
510         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
511         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_AND;
512
513         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
514         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME;
515         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_EQUAL;
516         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("INBOX");
517         filter_list[2].list_filter_item.rule.case_sensitivity              = true;
518         */
519
520         sorting_rule_list = malloc(sizeof(email_list_sorting_rule_t) * 2);
521         memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * 2);
522
523         sorting_rule_list[0].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT;
524         sorting_rule_list[0].sort_order                                    = EMAIL_SORT_ORDER_ASCEND;
525         sorting_rule_list[0].force_boolean_check                           = true;
526
527         sorting_rule_list[1].target_attribute                              = EMAIL_MAIL_ATTRIBUTE_DATE_TIME;
528         sorting_rule_list[1].sort_order                                    = EMAIL_SORT_ORDER_ASCEND;
529
530         err = email_get_mail_list_ex(filter_list, 9, sorting_rule_list, 2, -1, -1, &result_mail_list, &result_mail_count);
531
532         if(err == EMAIL_ERROR_NONE) {
533                 testapp_print("email_get_mail_list_ex succeed.\n");
534
535                 for(i = 0; i < result_mail_count; i++) {
536                         testapp_print("mail_id [%d], subject [%s], from [%s]\n", result_mail_list[i].mail_id, result_mail_list[i].subject, result_mail_list[i].from);
537                 }
538         }
539         else {
540                 testapp_print("email_get_mail_list_ex failed.\n");
541         }
542
543         email_free_list_filter(&filter_list, 9);
544
545         return FALSE;
546 }
547
548 static gboolean testapp_test_send_cancel ()
549 {
550         int num = 0;
551         int Y = 0;
552         int i = 0;
553         int j = 0;
554         int *mailIdList = NULL;
555         int mail_id = 0;
556         int result_from_scanf = 0;
557
558         testapp_print("\n > Enter total Number of mail  want to send: ");
559         result_from_scanf = scanf("%d", &num);
560         mailIdList = (int *)malloc(sizeof(int)*num);
561         if(!mailIdList)
562                 return false ;
563         
564         for(i = 1;i <=num ; i++) {
565                 testapp_test_mail_send(&mail_id);
566                 
567                 testapp_print("mail_id[%d]",mail_id);
568
569                 mailIdList[i] = mail_id;
570                 testapp_print("mailIdList[%d][%d]",i,mailIdList[i]);
571
572                 mail_id = 0;
573                 testapp_print("\n > Do you want to cancel the send mail job '1' or '0': ");
574                 result_from_scanf = scanf("%d", &Y);
575                 if(Y == 1) {
576                         testapp_print("\n >Enter mail-id[1-%d] ",i);
577                                 result_from_scanf = scanf("%d", &j);
578                         testapp_print("\n mailIdList[%d] ",mailIdList[j]);      
579                         if(email_cancel_sending_mail( mailIdList[j]) < 0)
580                                 testapp_print("email_cancel_sending_mail failed..!");
581                         else
582                                 testapp_print("email_cancel_sending_mail success..!");
583                 }
584         }
585         return FALSE;
586 }
587
588 static gboolean testapp_test_delete()
589 {
590         int mail_id=0, account_id =0;
591         int mailbox_id = 0;
592         int err = EMAIL_ERROR_NONE;
593         int from_server = 0;
594         int result_from_scanf = 0;
595
596         testapp_print("\n > Enter Account_id: ");
597         result_from_scanf = scanf("%d", &account_id);
598
599         testapp_print("\n > Enter Mail_id: ");
600         result_from_scanf = scanf("%d", &mail_id);
601         
602         testapp_print("\n > Enter Mailbox id: ");
603         result_from_scanf = scanf("%d", &mailbox_id);
604         
605         testapp_print("\n > Enter from_server: ");
606         result_from_scanf = scanf("%d", &from_server);
607
608         /* delete message */
609         if( (err = email_delete_mail(mailbox_id, &mail_id, 1, from_server)) < 0)
610                 testapp_print("\n email_delete_mail failed[%d]\n", err);
611         else
612                 testapp_print("\n email_delete_mail success\n");
613
614         return FALSE;
615 }
616
617
618
619 static gboolean testapp_test_move()
620 {
621         int mail_id[3];
622         int i = 0;
623         int mailbox_id = 0;
624         int result_from_scanf = 0;
625         
626         for(i = 0; i< 3; i++) {
627                 testapp_print("\n > Enter mail_id: ");
628                 result_from_scanf = scanf("%d",&mail_id[i]);
629         }
630         
631         testapp_print("\n > Enter mailbox_id: ");
632         result_from_scanf = scanf("%d", &mailbox_id);
633
634         /* move mail */
635         email_move_mail_to_mailbox(mail_id, 3, mailbox_id);
636         return FALSE;
637 }
638
639 static gboolean testapp_test_delete_all()
640 {
641         int mailbox_id =0;
642         int err = EMAIL_ERROR_NONE;
643         int result_from_scanf = 0;
644
645         testapp_print("\n > Enter mailbox_id: ");
646         result_from_scanf = scanf("%d",&mailbox_id);
647                                                 
648         /* delete all message */
649         if ( (err = email_delete_all_mails_in_mailbox(mailbox_id, 0)) < 0)
650                 testapp_print("email_delete_all_mails_in_mailbox failed [%d]\n", err);
651         else
652                 testapp_print("email_delete_all_mails_in_mailbox Success\n");   
653                                                                                                                         
654         return FALSE;
655 }
656
657
658 static gboolean testapp_test_add_attachment()
659 {       
660         int mail_id = 0;
661         int result_from_scanf = 0;
662         char arg[100];
663         email_attachment_data_t attachment;
664         
665         testapp_print("\n > Enter Mail Id: ");
666         result_from_scanf = scanf("%d", &mail_id);
667
668         memset(&attachment, 0x00, sizeof(email_attachment_data_t));
669         memset(arg, 0x00, 100);
670         testapp_print("\n > Enter attachment name: ");
671         result_from_scanf = scanf("%s",arg);
672         
673         attachment.attachment_name = strdup(arg);
674         
675         memset(arg, 0x00, 100);
676         testapp_print("\n > Enter attachment absolute path: ");
677         result_from_scanf = scanf("%s",arg);
678
679         attachment.save_status = true;
680         attachment.attachment_path = strdup(arg);
681         if(email_add_attachment(mail_id, &attachment) < 0)
682                 testapp_print("email_add_attachment failed\n"); 
683         else
684                 testapp_print("email_add_attachment success\n");
685
686
687         return FALSE;
688
689 }
690
691 static gboolean testapp_test_set_deleted_flag()
692 {
693         int index = 0;
694         int account_id = 0;
695         int mail_ids[100] = { 0, };
696         int temp_mail_id = 0;
697         int err_code = EMAIL_ERROR_NONE;
698         int result_from_scanf = 0;
699
700         testapp_print("\n >>> Input target account id: ");
701         result_from_scanf = scanf("%d", &account_id);
702
703         do {
704                 testapp_print("\n >>> Input target mail id ( Input 0 to terminate ) [MAX = 100]: ");
705                 result_from_scanf = scanf("%d", &temp_mail_id);
706                 mail_ids[index++] = temp_mail_id;
707         } while (temp_mail_id != 0);
708
709         err_code = email_set_flags_field(account_id, mail_ids, index, EMAIL_FLAGS_DELETED_FIELD, 1, true);
710         testapp_print("email_set_flags_field returns - err[%d]\n", err_code);
711
712         return 0;
713 }
714
715 static gboolean testapp_test_expunge_mails_deleted_flagged()
716 {
717         int mailbox_id = 0;
718         int on_server = 0;
719         int err_code = EMAIL_ERROR_NONE;
720         unsigned handle = 0;
721         int result_from_scanf = 0;
722
723         testapp_print("\n >>> Input target mailbox id: ");
724         result_from_scanf = scanf("%d", &mailbox_id);
725
726         testapp_print("\n >>> Expunge on server?: ");
727         result_from_scanf = scanf("%d", &on_server);
728
729         err_code = email_expunge_mails_deleted_flagged(mailbox_id, on_server, &handle);
730
731         testapp_print("email_expunge_mails_deleted_flagged returns - err[%d]\n", err_code);
732
733         return 0;
734 }
735
736 static gboolean testapp_test_get_mail_list_ex()
737 {
738         testapp_print("\n >>> testapp_test_get_mail_list_ex : Entered \n");
739         email_mail_list_item_t *mail_list = NULL, **mail_list_pointer = NULL;
740         int mailbox_id = 0;
741         int count = 0, i = 0;
742         int account_id = 0;
743         int start_index =0;
744         int limit_count = 0;
745         int sorting = 0;
746         int err_code = EMAIL_ERROR_NONE;
747         int to_get_count = 0;
748         int is_for_thread_view = 0;
749         int list_type;
750         struct tm *temp_time_info;
751         int result_from_scanf = 0;
752
753         testapp_print("\n > Enter Account_id (0 = all accounts) : ");
754         result_from_scanf = scanf("%d",&account_id);
755
756         testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :");
757         result_from_scanf = scanf("%d", &mailbox_id);
758
759         testapp_print("\n > Enter Sorting : ");
760         result_from_scanf = scanf("%d",&sorting);
761         
762         testapp_print("\n > Enter Start index (starting at 0): ");
763         result_from_scanf = scanf("%d",&start_index);
764
765         testapp_print("\n > Enter max_count : ");
766         result_from_scanf = scanf("%d",&limit_count);
767
768         testapp_print("\n > For thread view : ");
769         result_from_scanf = scanf("%d",&is_for_thread_view);
770
771         testapp_print("\n > Count mails?(1: YES):");
772         result_from_scanf = scanf("%d",&to_get_count);
773
774         if(to_get_count)
775                 mail_list_pointer = NULL;
776         else
777                 mail_list_pointer = &mail_list;
778         
779         if(is_for_thread_view == -2) {
780                 list_type = EMAIL_LIST_TYPE_LOCAL;
781         }
782         else if(is_for_thread_view == -1)
783                 list_type = EMAIL_LIST_TYPE_THREAD;
784         else
785                 list_type = EMAIL_LIST_TYPE_NORMAL;
786         
787         /* Get mail list */
788         if( mailbox_id == 0) {
789                 testapp_print("Calling email_get_mail_list for all mailbox.\n");
790                 err_code = email_get_mail_list(account_id, 0, list_type, start_index, limit_count, sorting,  mail_list_pointer, &count);
791                 if ( err_code < 0) 
792                         testapp_print("email_get_mail_list failed - err[%d]\n", err_code);
793         }
794         else {
795                 testapp_print("Calling email_get_mail_list for %d mailbox_id.\n", mailbox_id);
796                 err_code = email_get_mail_list(account_id, mailbox_id, list_type, start_index, limit_count, sorting,  mail_list_pointer, &count);
797                 if ( err_code < 0) 
798                         testapp_print("email_get_mail_list failed - err[%d]\n", err_code);
799         }
800         testapp_print("email_get_mail_list >>>>>>count - %d\n",count);
801
802         if (mail_list) {
803                 for (i=0; i< count; i++) {
804                         testapp_print("\n[%d]\n", i);
805                         testapp_print(" >>> mailbox_id [ %d ] \n", mail_list[i].mailbox_id);
806                         testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
807                         testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
808                         if (  mail_list[i].from != NULL )
809                                 testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
810                         if (  mail_list[i].recipients != NULL )
811                                 testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
812                         if (  mail_list[i].subject != NULL )
813                                 testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
814                         testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
815                         temp_time_info = localtime(&mail_list[i].date_time);
816                         testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
817                                                                 temp_time_info->tm_year + 1900,
818                                                                 temp_time_info->tm_mon+1,
819                                                                 temp_time_info->tm_mday,
820                                                                 temp_time_info->tm_hour,
821                                                                 temp_time_info->tm_min,
822                                                                 temp_time_info->tm_sec);
823                         testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
824                         testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
825                         testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
826                         testapp_print(" >>> is_locked [ %d ] \n", mail_list[i].is_locked);
827                         testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
828                         if (  mail_list[i].previewBodyText != NULL )
829                                 testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
830                 }
831                 free(mail_list);
832         }
833         
834         testapp_print("\n >>> email_get_mail_list : End \n");
835         return 0;
836 }
837
838
839 static gboolean testapp_test_get_mail_list_for_thread_view()
840 {
841         testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : Entered \n");
842         email_mail_list_item_t *mail_list = NULL;
843         int count = 0, i = 0;
844         int account_id = 0;
845         int err_code = EMAIL_ERROR_NONE;
846         struct tm *time_info;
847
848         /* Get mail list */
849         if ( email_get_mail_list(account_id, 0 , EMAIL_LIST_TYPE_THREAD, 0, 500, EMAIL_SORT_DATETIME_HIGH, &mail_list, &count) < 0)  {
850                 testapp_print("email_get_mail_list failed : %d\n",err_code);
851                 return FALSE;
852         }
853         testapp_print("email_get_mail_list >>>>>>count - %d\n",count);
854         if (mail_list) {
855                 for (i=0; i< count; i++) {
856                         testapp_print(" i [%d]\n", i);
857                         testapp_print(" >>> Mail ID [ %d ] \n", mail_list[i].mail_id);
858                         testapp_print(" >>> Account ID [ %d ] \n", mail_list[i].account_id);
859                         testapp_print(" >>> Mailbox id [ %d ] \n", mail_list[i].mailbox_id);
860                         testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
861                         testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
862                         testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
863                         testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
864                         time_info = localtime(&mail_list[i].date_time);
865                         testapp_print(" >>> date_time [ %s ] \n", asctime(time_info));
866                         testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
867                         testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
868                         testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
869                         testapp_print(" >>> lock [ %d ] \n", mail_list[i].is_locked);
870                         testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
871                         testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
872                         testapp_print(" >>> thread_id [ %d ] \n", mail_list[i].thread_id);
873                         testapp_print(" >>> thread__item_count [ %d ] \n", mail_list[i].thread_item_count);
874                 }
875                 free(mail_list);
876         }       
877         testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : End \n");
878         return 0;
879 }
880
881 static gboolean testapp_test_count ()
882 {
883         int total = 0;
884         int unseen = 0;
885         email_list_filter_t *filter_list = NULL;
886
887         filter_list = malloc(sizeof(email_list_filter_t) * 3);
888         memset(filter_list, 0 , sizeof(email_list_filter_t) * 3);
889
890         filter_list[0].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
891         filter_list[0].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
892         filter_list[0].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
893         filter_list[0].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
894         filter_list[0].list_filter_item.rule.case_sensitivity              = false;
895
896         filter_list[1].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_OPERATOR;
897         filter_list[1].list_filter_item.operator_type                      = EMAIL_LIST_FILTER_OPERATOR_OR;
898
899         filter_list[2].list_filter_item_type                               = EMAIL_LIST_FILTER_ITEM_RULE;
900         filter_list[2].list_filter_item.rule.target_attribute              = EMAIL_MAIL_ATTRIBUTE_TO;
901         filter_list[2].list_filter_item.rule.rule_type                     = EMAIL_LIST_FILTER_RULE_INCLUDE;
902         filter_list[2].list_filter_item.rule.key_value.string_type_value   = strdup("RE");
903         filter_list[2].list_filter_item.rule.case_sensitivity              = false;
904
905         if(EMAIL_ERROR_NONE == email_count_mail(filter_list, 3, &total, &unseen))
906                 printf("\n Total: %d, Unseen: %d \n", total, unseen);
907         return 0;
908 }
909
910 static gboolean testapp_test_set_flags_field ()
911 {
912         int account_id = 0;
913         int mail_id = 0;
914         int result_from_scanf = 0;
915
916         testapp_print("\n > Enter Account ID: ");
917         result_from_scanf = scanf("%d", &account_id);
918         
919         testapp_print("\n > Enter Mail ID: ");
920         result_from_scanf = scanf("%d", &mail_id);
921
922         if(email_set_flags_field(account_id, &mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, 1, 1) < 0)
923                 testapp_print("email_set_flags_field failed");
924         else
925                 testapp_print("email_set_flags_field success");
926                 
927         return TRUE;
928 }
929
930 static gboolean testapp_test_download_body ()
931 {
932         int mail_id = 0;
933         unsigned handle = 0, err;
934         int result_from_scanf = 0;
935
936         testapp_print("\n > Enter Mail Id: ");
937         result_from_scanf = scanf("%d", &mail_id);
938         err = email_download_body(mail_id, 0, &handle);
939         if(err  < 0)
940                 testapp_print("email_download_body failed");
941         else {
942                 testapp_print("email_download_body success");
943                 testapp_print("handle[%d]\n", handle);
944         }
945         return TRUE;
946 }
947
948
949 static gboolean testapp_test_cancel_download_body ()
950 {
951         int mail_id = 0;
952         int account_id = 0;
953         int yes = 0;
954         unsigned handle = 0;
955         int result_from_scanf = 0;
956         
957         email_mailbox_t mailbox;
958         memset(&mailbox, 0x00, sizeof(email_mailbox_t));
959
960         testapp_print("\n > Enter account_id: ");
961         result_from_scanf = scanf("%d", &account_id);
962
963         testapp_print("\n > Enter mail id: ");
964         result_from_scanf = scanf("%d", &mail_id);
965         
966         if( email_download_body(mail_id, 0, &handle) < 0)
967                 testapp_print("email_download_body failed");
968         else {
969                 testapp_print("email_download_body success\n");
970                 testapp_print("Do u want to cancel download job>>>>>1/0\n");
971                 result_from_scanf = scanf("%d",&yes);
972                 if(1 == yes) {
973                         if(email_cancel_job(account_id, handle , EMAIL_CANCELED_BY_USER) < 0)
974                                 testapp_print("email_cancel_job failed..!");
975                         else {
976                                 testapp_print("email_cancel_job success..!");
977                                 testapp_print("handle[%d]\n", handle);
978                         }
979                 }
980                         
981         }
982         return TRUE;
983 }
984 static gboolean testapp_test_download_attachment ()
985 {
986         int mail_id = 0;
987         int attachment_no = 0;
988         unsigned handle = 0;
989         int result_from_scanf = 0;
990         
991         testapp_print("\n > Enter Mail Id: ");
992         result_from_scanf = scanf("%d", &mail_id);
993
994         testapp_print("\n > Enter attachment number: ");
995         result_from_scanf = scanf("%d", &attachment_no);
996         
997         if( email_download_attachment(mail_id, attachment_no ,&handle) < 0)
998                 testapp_print("email_download_attachment failed");
999         else {
1000                 testapp_print("email_download_attachment success");
1001                 testapp_print("handle[%d]\n", handle);
1002         }
1003         return TRUE;
1004
1005 }
1006
1007 static gboolean testapp_test_retry_send()
1008 {
1009         int mail_id = 0;
1010         int timeout = 0;
1011         int result_from_scanf = 0;
1012         
1013         email_mailbox_t mailbox;
1014         memset(&mailbox, 0x00, sizeof(email_mailbox_t));
1015
1016         testapp_print("\n > Enter Mail Id: ");
1017         result_from_scanf = scanf("%d", &mail_id);
1018         
1019         testapp_print("\n > Enter timeout in seconds: ");
1020         result_from_scanf = scanf("%d", &timeout);
1021
1022         if( email_retry_sending_mail(mail_id, timeout) < 0)
1023                 testapp_print("email_retry_sending_mail failed");               
1024         return TRUE;            
1025 }
1026
1027 static gboolean testapp_test_move_all_mails_to_mailbox()
1028 {
1029         int err = EMAIL_ERROR_NONE;
1030         int result_from_scanf = 0;
1031         int src_mailbox_id;
1032         int dest_mailbox_id;
1033
1034         testapp_print("src mailbox id> ");
1035         result_from_scanf = scanf("%d", &src_mailbox_id);
1036
1037         testapp_print("dest mailbox id> ");
1038         result_from_scanf = scanf("%d", &dest_mailbox_id);
1039         
1040         err = email_move_all_mails_to_mailbox(src_mailbox_id, dest_mailbox_id);
1041         if ( err < 0 ) {
1042                 testapp_print("email_move_all_mails_to_mailbox failed: err[%d]\n", err);
1043         }
1044         else {
1045                 testapp_print("email_move_all_mails_to_mailbox suceeded\n");
1046         }
1047
1048         return false;
1049 }
1050
1051 static gboolean testapp_test_get_totaldiskusage()
1052 {
1053         unsigned long total_size = 0;
1054         int err_code = EMAIL_ERROR_NONE ;
1055         
1056         err_code = email_get_disk_space_usage(&total_size);
1057         if ( err_code < 0)
1058                 testapp_print("email_get_disk_space_usage failed err : %d\n",err_code);
1059         else
1060                 testapp_print("email_get_disk_space_usage SUCCESS, total disk usage in KB : %ld \n", total_size);               
1061
1062         return FALSE;
1063 }
1064
1065
1066
1067 static gboolean testapp_test_db_test()
1068 {
1069         int err = EMAIL_ERROR_NONE;
1070         int result_from_scanf = 0;
1071         int mail_id;
1072         int account_id;
1073         char *to = NULL;
1074         char *cc = NULL;
1075         char *bcc = NULL;
1076
1077         to = (char *) malloc(500000);
1078         cc = (char *) malloc(500000);
1079         bcc = (char *) malloc(500000);
1080         
1081         memset(to, 0x00, sizeof(to));
1082         memset(cc, 0x00, sizeof(to));
1083         memset(bcc, 0x00, sizeof(to));
1084
1085         testapp_print("Input Mail id:\n");
1086         result_from_scanf = scanf("%d", &mail_id);
1087         testapp_print("Input Account id:\n");
1088         result_from_scanf = scanf("%d", &account_id);
1089         testapp_print("Input TO field:\n");
1090         result_from_scanf = scanf("%s", to);
1091         testapp_print("Input CC field:\n");
1092         result_from_scanf = scanf("%s", cc);
1093         testapp_print("Input BCC field:\n");
1094         result_from_scanf = scanf("%s", bcc);
1095         
1096         if ( emstorage_test(mail_id, account_id, to, cc, bcc, &err) == true ) {
1097                 testapp_print(">> Saving Succeeded\n");
1098         }
1099         else {
1100                 testapp_print(">> Saving Failed[%d]\n", err);
1101         }
1102         
1103         free(to);
1104         free(cc);
1105         free(bcc);
1106         
1107         return false;
1108 }
1109
1110 static gboolean testapp_test_address_format_check_test()
1111 {
1112         /*
1113         int i;
1114         int type;
1115         int index;
1116         int check_yn;
1117         int err = EMAIL_ERROR_NONE;
1118         char *pAddress = NULL;
1119         char input_address[8096];
1120         char *address_list[] = {
1121                 "tom@gmail.com",
1122                 "tom@gmail,com",
1123                 "tom@gmail.com@gmail.com",
1124                 "[tom@gmail.com]",
1125                 "\"Tom\"<tom@gmail.com>", 
1126                 "\"Tom\"[tom@gmail.com]",
1127                 "\"Tom\"<tom,@gmail.com>",
1128                 "<tom@gmail.com>",
1129                 "<tom@gmail,com>",
1130                 "<tom@gmail.>",
1131                 "<tom@gmail.com>,tom@gmail.com",
1132                 "<tom@gmail.com>;tom@gmail.com",
1133                 "tom @gmail.com",
1134                 "tom@ gmail.com",
1135                 "tom@gmail..com",
1136                 "tom@",
1137                 "tom@gmail",
1138                 "tom@gmail.",
1139                 "tom@gmail.c",
1140                 "tom@.",
1141                 "\"\"Tom\"<tom,@gmail.com>",
1142                 "tom@gmail.com,tom@gmail.com",
1143                 "tom@gmail.com.",
1144                 "<tom@gmail.com>,tom@.gmail.com",
1145                 "&& tom@live.com ----",
1146                 "madhu <tom@gmail.com>",
1147                 "tom@gmail.com, && tom@live.com",
1148                 "tom@gmail.com , && tom@live.com",
1149                 "< tom@gmail.com    > , <           tom@.gmail.com     >",
1150                 "tom@gmail.com ,           tom@gmail.com",
1151                 "<tom@gmail.com          >",
1152                 "<to     m@gmail.com          >",
1153                 "<tom@gmail.com>;tom@gmail.com",        
1154                "Tom< tom@gmail.com > ,       Tom <tom@gmail.com>",      
1155                 " \"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>",
1156                 "<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>",
1157                 "             tom@gmail.com         ;   <  tom@gmail.com   > ",
1158                 "\"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>  ",
1159                 "             \"tomtom\" <tom@aol.com>    ;\"tomtom\" <tom@aol.com> ;          ",
1160                 "  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> ;    ",
1161                 "<tom@aol.com>    , \"tomtomtomtom\" <tom@live.com>,\"Tom\"  < tom@gmail.com> ;    ",
1162                 " 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>",
1163                 NULL
1164         };
1165         int address_count = 0;
1166         
1167         testapp_print("Select input method:\n");
1168         testapp_print("1. Test data\n");
1169         testapp_print("2. Keyboard\n");
1170         result_from_scanf = scanf("%d", &type);
1171
1172         switch ( type ) {
1173                 case 1:
1174                         do  {
1175                                 for ( i = 0; address_list[i] != NULL; i++ ) {
1176                                         testapp_print("[%d] addr[%s]\n", i, address_list[i]);
1177                                         address_count++;
1178                                 }
1179                                 testapp_print("Choose address to be tested:[99:quit]\n");
1180                                 result_from_scanf = scanf("%d", &index);
1181                                 if ( index == 99 )
1182                                         break;
1183
1184                                 testapp_print(">> [%d] Checking? (1:Yes, Other:No) [%s]\n", index, address_list[index]);
1185                                 result_from_scanf = scanf("%d", &check_yn);
1186                                 if ( check_yn == 1 ) {
1187                                         pAddress = strdup(address_list[index]);
1188                                         if ( em_verify_email_address(pAddress, false, &err ) == true ) {
1189                                                 testapp_print("<< [%d] Checking Succeeded : addr[%s]\n", index, address_list[index]);
1190                                         }
1191                                         else {
1192                                                 testapp_print("<< [%d] Checking Failed    : addr[%s], err[%d]\n", index, address_list[index], err);
1193                                         }                       
1194                                         if(pAddress) {
1195                                                 free(pAddress);
1196                                                 pAddress = NULL;
1197                                         }
1198                                 }
1199                                 else {
1200                                         testapp_print("<< [%d]  Skipped            : addr[%s]\n", index, address_list[index]);
1201                                 }
1202                         } 
1203                         while (1);
1204                         break;
1205                 case 2:
1206                         testapp_print("Input address: \n");
1207                         result_from_scanf = scanf("%s", input_address);
1208                         if ( em_verify_email_address(input_address, false, &err ) == true ) {
1209                                 testapp_print(">> Saving Succeeded : addr[%s]\n", input_address);
1210                         }
1211                         else {
1212                                 testapp_print(">> Saving Failed : addr[%s], err[%d]\n", input_address, err);
1213                         }
1214                         break;
1215                 default:
1216                         testapp_print("wrong nuber... [%d]\n", type);
1217                         break;
1218         }
1219         */
1220         return FALSE;
1221 }
1222
1223 static gboolean testapp_test_get_max_mail_count()
1224 {
1225         int max_count = -1;
1226         int err = EMAIL_ERROR_NONE;
1227
1228         err = email_get_max_mail_count(&max_count);
1229         testapp_print("\n\t>>>>> email_get_max_mail_count() return [%d]\n\n", max_count);
1230         
1231         return false;
1232 }
1233
1234 #include "email-storage.h"
1235 static gboolean testapp_test_test_get_thread_information()
1236 {
1237         int error_code, thread_id= 38;
1238         email_mail_list_item_t *result_mail;
1239         
1240         if( (error_code = email_get_thread_information_ex(thread_id, &result_mail)) == EMAIL_ERROR_NONE) {
1241                 testapp_print("email_get_thread_information returns = %d\n", error_code);
1242                 testapp_print("subject = %s\n", result_mail->subject);
1243                 testapp_print("mail_id = %d\n", result_mail->mail_id);
1244                 testapp_print("from = %s\n", result_mail->from);
1245                 testapp_print("thrad_id = %d\n", result_mail->thread_id);
1246                 testapp_print("count = %d\n", result_mail->thread_item_count);
1247         }
1248
1249         return TRUE;
1250 }
1251
1252 static gboolean testapp_test_get_address_info_list()
1253 {
1254         testapp_print(" >>> testapp_test_get_address_info_list : Entered \n");
1255
1256         char buf[1024];
1257         int i = 0;
1258         int mail_id = 0;
1259         int result_from_scanf = 0;
1260         email_address_info_list_t *address_info_list= NULL;
1261         email_address_info_t *p_address_info = NULL;
1262         GList *list = NULL;
1263         GList *node = NULL;
1264
1265         memset(buf, 0x00, sizeof(buf));
1266         testapp_print("\n > Enter mail_id: ");
1267         result_from_scanf = scanf("%d",&mail_id);
1268
1269         email_get_address_info_list(mail_id, &address_info_list);
1270
1271         testapp_print("===================================================\n");
1272         testapp_print("\t\t\t address info list\n");
1273         testapp_print("===================================================\n");
1274         testapp_print("address_type\t address \t\tdisplay_name\t contact id\n");
1275         testapp_print("===================================================\n");
1276
1277         for ( i = EMAIL_ADDRESS_TYPE_FROM; i <= EMAIL_ADDRESS_TYPE_BCC; i++ ) {
1278                 switch ( i ) {
1279                         case EMAIL_ADDRESS_TYPE_FROM:
1280                                 list = address_info_list->from;
1281                                 break;
1282                         case EMAIL_ADDRESS_TYPE_TO:
1283                                 list = address_info_list->to;
1284                                 break;
1285                         case EMAIL_ADDRESS_TYPE_CC:
1286                                 list = address_info_list->cc;
1287                                 break;
1288                         case EMAIL_ADDRESS_TYPE_BCC:
1289                                 list = address_info_list->bcc;
1290                                 break;
1291                 }
1292
1293                 /*  delete dynamic-allocated memory for each item */
1294                 node = g_list_first(list);
1295                 while ( node != NULL ) {
1296                         p_address_info = (email_address_info_t*)node->data;
1297                         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);
1298
1299                         node = g_list_next(node);
1300                 }
1301                 testapp_print("\n");
1302         }
1303         testapp_print("===================================================\n");
1304
1305         if(address_info_list)
1306                 email_free_address_info_list(&address_info_list);
1307
1308         testapp_print(" >>> testapp_test_get_address_info_list : END \n");
1309         return TRUE;
1310 }
1311
1312 static gboolean testapp_test_search_mail_on_server()
1313 {
1314         testapp_print(" >>> testapp_test_search_mail_on_server : Entered \n");
1315
1316         int err_code = EMAIL_ERROR_NONE;
1317         int account_id = 0;
1318         int mailbox_id = 0;
1319         int search_key_value_integer = 0;
1320         int result_from_scanf = 0;
1321         email_search_filter_type search_filter_type = 0;
1322         email_search_filter_t search_filter;
1323         unsigned int handle = 0;
1324         char search_key_value_string[MAX_EMAIL_ADDRESS_LENGTH];
1325
1326         testapp_print("input account id : ");
1327         result_from_scanf = scanf("%d",&account_id);
1328
1329         testapp_print("input mailbox id : ");
1330         result_from_scanf = scanf("%d", &mailbox_id);
1331
1332         testapp_print(
1333                 "       EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO       =  1,  ( integet type ) \n"
1334                 "       EMAIL_SEARCH_FILTER_TYPE_UID              =  2,  ( integet type ) \n"
1335                 "       EMAIL_SEARCH_FILTER_TYPE_BCC              =  7,  ( string type ) \n"
1336                 "       EMAIL_SEARCH_FILTER_TYPE_CC               =  9,  ( string type ) \n"
1337                 "       EMAIL_SEARCH_FILTER_TYPE_FROM             = 10,  ( string type ) \n"
1338                 "       EMAIL_SEARCH_FILTER_TYPE_KEYWORD          = 11,  ( string type ) \n"
1339                 "       EMAIL_SEARCH_FILTER_TYPE_SUBJECT          = 13,  ( string type ) \n"
1340                 "       EMAIL_SEARCH_FILTER_TYPE_TO               = 15,  ( string type ) \n"
1341                 "       EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER      = 16,  ( integet type ) \n"
1342                 "       EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER     = 17,  ( integet type ) \n"
1343                 "       EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20,  ( time type ) \n"
1344                 "       EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON     = 21,  ( time type ) \n"
1345                 "       EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE  = 22,  ( time type ) \n"
1346                 "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED   = 26,  ( integet type ) \n"
1347                 "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED    = 28,  ( integet type ) \n"
1348                 "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT      = 30,  ( integet type ) \n"
1349                 "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED     = 32,  ( integet type ) \n"
1350                 "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT     = 34,  ( integet type ) \n"
1351                 "       EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN       = 36,  ( integet type ) \n"
1352                 "       EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID       = 43,  ( string type ) \n");
1353         testapp_print("input search filter type : ");
1354         result_from_scanf = scanf("%d", (int*)&search_filter_type);
1355
1356         search_filter.search_filter_type = search_filter_type;
1357
1358         switch(search_filter_type) {
1359                 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO       :
1360                 case EMAIL_SEARCH_FILTER_TYPE_UID              :
1361                 case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER      :
1362                 case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER     :
1363                 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED   :
1364                 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED    :
1365                 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT      :
1366                 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED     :
1367                 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT     :
1368                 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN       :
1369                         testapp_print("input search filter key value : ");
1370                         result_from_scanf = scanf("%d", &search_key_value_integer);
1371                         search_filter.search_filter_key_value.integer_type_key_value = search_key_value_integer;
1372                         break;
1373
1374                 case EMAIL_SEARCH_FILTER_TYPE_BCC              :
1375                 case EMAIL_SEARCH_FILTER_TYPE_CC               :
1376                 case EMAIL_SEARCH_FILTER_TYPE_FROM             :
1377                 case EMAIL_SEARCH_FILTER_TYPE_KEYWORD          :
1378                 case EMAIL_SEARCH_FILTER_TYPE_SUBJECT          :
1379                 case EMAIL_SEARCH_FILTER_TYPE_TO               :
1380                 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID       :
1381                         testapp_print("input search filter key value : ");
1382                         result_from_scanf = scanf("%s", search_key_value_string);
1383                         search_filter.search_filter_key_value.string_type_key_value = search_key_value_string;
1384                         break;
1385
1386                 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
1387                 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON     :
1388                 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE  :
1389                         testapp_print("input search filter key value (format = YYYYMMDDHHMMSS) : ");
1390                         result_from_scanf = scanf("%s", search_key_value_string);
1391                         /* TODO : write codes for converting string to time */
1392                         /* search_filter.search_filter_key_value.time_type_key_value = search_key_value_string; */
1393                         break;
1394                 default :
1395                         testapp_print("Invalid filter type [%d]", search_filter_type);
1396                         return FALSE;
1397         }
1398
1399         if( (err_code = email_search_mail_on_server(account_id, mailbox_id, &search_filter,1, &handle)) != EMAIL_ERROR_NONE) {
1400                 testapp_print("email_search_mail_on_server failed [%d]", err_code);
1401         }
1402
1403         testapp_print(" >>> testapp_test_search_mail_on_server : END \n");
1404         return TRUE;
1405 }
1406
1407 static gboolean testapp_test_add_mail_to_search_result_box()
1408 {
1409         int                    i = 0;
1410         int                    account_id = 0;
1411         int                    from_eas = 0;
1412         int                    attachment_count = 0;
1413         int                    err = EMAIL_ERROR_NONE;
1414         int                    result_from_scanf = 0;
1415         char                   arg[50] = { 0 , };
1416         char                  *body_file_path = MAIL_TEMP_BODY;
1417         email_mailbox_t         *mailbox_data = NULL;
1418         email_mail_data_t       *test_mail_data = NULL;
1419         email_attachment_data_t *attachment_data = NULL;
1420         email_meeting_request_t *meeting_req = NULL;
1421         FILE                  *body_file = NULL;
1422
1423         testapp_print("\n > Enter account id : ");
1424         result_from_scanf = scanf("%d", &account_id);
1425
1426         email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &mailbox_data);
1427
1428         test_mail_data = malloc(sizeof(email_mail_data_t));
1429         memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
1430
1431         testapp_print("\n From EAS? [0/1]> ");
1432         result_from_scanf = scanf("%d", &from_eas);
1433
1434         test_mail_data->account_id           = account_id;
1435         test_mail_data->save_status          = 1;
1436         test_mail_data->body_download_status = 1;
1437         test_mail_data->flags_seen_field     = 1;
1438         test_mail_data->file_path_plain      = strdup(body_file_path);
1439         test_mail_data->mailbox_id           = mailbox_data->mailbox_id;
1440         test_mail_data->mailbox_type         = mailbox_data->mailbox_type;
1441         test_mail_data->full_address_from    = strdup("<test1@test.com>");
1442         test_mail_data->full_address_to      = strdup("<test2@test.com>");
1443         test_mail_data->full_address_cc      = strdup("<test3@test.com>");
1444         test_mail_data->full_address_bcc     = strdup("<test4@test.com>");
1445         test_mail_data->subject              = strdup("Into search result mailbox");
1446
1447         body_file = fopen(body_file_path, "w");
1448
1449         for(i = 0; i < 500; i++)
1450                 fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
1451         fflush(body_file);
1452         fclose(body_file);
1453
1454         testapp_print(" > Attach file? [0/1] : ");
1455         result_from_scanf = scanf("%d",&attachment_count);
1456
1457         if ( attachment_count )  {
1458                 memset(arg, 0x00, 50);
1459                 testapp_print("\n > Enter attachment name : ");
1460                 result_from_scanf = scanf("%s", arg);
1461
1462                 attachment_data = malloc(sizeof(email_attachment_data_t));
1463
1464                 attachment_data->attachment_name  = strdup(arg);
1465
1466                 memset(arg, 0x00, 50);
1467                 testapp_print("\n > Enter attachment absolute path : ");
1468                 result_from_scanf = scanf("%s",arg);
1469
1470                 attachment_data->attachment_path  = strdup(arg);
1471                 attachment_data->save_status      = 1;
1472                 test_mail_data->attachment_count  = attachment_count;
1473         }
1474
1475         testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
1476         result_from_scanf = scanf("%d", &(test_mail_data->meeting_request_status));
1477
1478         if ( test_mail_data->meeting_request_status == 1
1479                 || test_mail_data->meeting_request_status == 2 ) {
1480                 time_t current_time;
1481                 /*  dummy data for meeting request */
1482                 meeting_req = malloc(sizeof(email_meeting_request_t));
1483                 memset(meeting_req, 0x00, sizeof(email_meeting_request_t));
1484
1485                 meeting_req->meeting_response     = 1;
1486                 current_time = time(NULL);
1487                 gmtime_r(&current_time, &(meeting_req->start_time));
1488                 gmtime_r(&current_time, &(meeting_req->end_time));
1489                 meeting_req->location = malloc(strlen("Seoul") + 1);
1490                 memset(meeting_req->location, 0x00, strlen("Seoul") + 1);
1491                 strcpy(meeting_req->location, "Seoul");
1492                 strcpy(meeting_req->global_object_id, "abcdef12345");
1493
1494                 meeting_req->time_zone.offset_from_GMT = 9;
1495                 strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
1496                 gmtime_r(&current_time, &(meeting_req->time_zone.standard_time_start_date));
1497                 meeting_req->time_zone.standard_bias = 3;
1498
1499                 strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
1500                 gmtime_r(&current_time, &(meeting_req->time_zone.daylight_time_start_date));
1501                 meeting_req->time_zone.daylight_bias = 7;
1502
1503         }
1504
1505         if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE)
1506                 testapp_print("email_add_mail failed. [%d]\n", err);
1507         else
1508                 testapp_print("email_add_mail success.\n");
1509
1510         testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
1511
1512         if(attachment_data)
1513                 email_free_attachment_data(&attachment_data, attachment_count);
1514
1515         if(meeting_req)
1516                 email_free_meeting_request(&meeting_req, 1);
1517
1518         email_free_mail_data(&test_mail_data, 1);
1519         email_free_mailbox(&mailbox_data, 1);
1520
1521         return FALSE;
1522 }
1523
1524 static gboolean testapp_test_email_load_eml_file()
1525 {
1526         email_mail_data_t *mail_data = NULL;
1527         email_attachment_data_t *mail_attachment_data = NULL;
1528         int i = 0;
1529         int attachment_count = 0;
1530         int err = EMAIL_ERROR_NONE;
1531         int result_from_scanf = 0;
1532         char eml_file_path[255] = {0, };
1533
1534         testapp_print("Input eml file path : ");
1535         result_from_scanf = scanf("%s", eml_file_path);
1536
1537         if ((err = email_open_eml_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE)
1538         {
1539                 testapp_print("email_open_eml_file failed : [%d]\n", err);
1540                 return false;   
1541         }
1542         
1543         testapp_print("load success\n");
1544         testapp_print("Return-Path: %s\n", mail_data->full_address_return);
1545         testapp_print("To: %s\n", mail_data->full_address_to);
1546         testapp_print("Subject: %s\n", mail_data->subject);
1547         testapp_print("From: %s\n", mail_data->full_address_from);
1548         testapp_print("Reply-To: %s\n", mail_data->full_address_reply);
1549         testapp_print("Sender: %s\n", mail_data->email_address_sender);
1550         testapp_print("Message-ID: %s\n", mail_data->message_id);
1551         testapp_print("attachment_count: %d\n", mail_data->attachment_count);
1552         testapp_print("inline content count : %d\n", mail_data->inline_content_count);
1553
1554         for (i = 0;i < mail_data->attachment_count ; i++) {
1555                 testapp_print("attachment_id: %d\n", mail_attachment_data[i].attachment_id);
1556                 testapp_print("inline_attachment_status: %d\n", mail_attachment_data[i].inline_content_status);
1557                 testapp_print("attachment_name: %s\n", mail_attachment_data[i].attachment_name);
1558                 testapp_print("attachment_path: %s\n", mail_attachment_data[i].attachment_path);
1559                 testapp_print("mailbox_id: %d\n", mail_attachment_data[i].mailbox_id);
1560         }
1561
1562         testapp_print("Success : Open eml file\n");
1563         
1564         if ((err = email_delete_eml_data(mail_data)) != EMAIL_ERROR_NONE) {
1565                 testapp_print("email_delete_eml_data failed : [%d]\n", err);
1566                 return false;
1567         }
1568
1569         testapp_print("Success : email_delete_eml_data\n");
1570
1571         if (mail_data)
1572                 email_free_mail_data(&mail_data, 1);
1573         
1574         testapp_print("Success : email_free_mail_data\n");
1575
1576         if (mail_attachment_data)
1577                 email_free_attachment_data(&mail_attachment_data, attachment_count);
1578
1579         testapp_print("Success : email_free_attachment_data\n");
1580
1581         return true;
1582
1583 }
1584
1585 /* internal functions */
1586 static gboolean testapp_test_interpret_command (int menu_number)
1587 {
1588         gboolean go_to_loop = TRUE;
1589         
1590         switch (menu_number) {
1591                 case 1:
1592                         testapp_test_get_mails();
1593                         break;
1594                 case 2:
1595                         testapp_test_mail_send(NULL);
1596                         break;
1597                 case 3:
1598                         testapp_test_get_mail_list();
1599                         break;
1600                 case 4:
1601                         testapp_test_add_attachment();
1602                         break;                  
1603                 case 5:
1604                         testapp_test_set_deleted_flag();
1605                         break;
1606                 case 6:
1607                         testapp_test_expunge_mails_deleted_flagged();
1608                         break;
1609                 case 9:
1610                         testapp_test_count();
1611                         break;
1612                 case 14:
1613                         testapp_test_delete();
1614                         break;
1615                 case 16:
1616                         testapp_test_download_body();
1617                         break;
1618                 case 17:
1619                         testapp_test_download_attachment();
1620                         break;          
1621                 case 20:
1622                         testapp_test_delete_all();
1623                         break;
1624                 case 21:
1625                         testapp_test_move();
1626                         break;
1627                 case 23:
1628                         testapp_test_retry_send();
1629                         break;
1630                 case 27:
1631                         testapp_test_move_all_mails_to_mailbox();
1632                         break;
1633                 case 38:
1634                         testapp_test_get_totaldiskusage();
1635                         break;
1636                 case 40:
1637                         testapp_test_address_format_check_test();
1638                         break;
1639                 case 41:
1640                         testapp_test_get_max_mail_count();
1641                         break;
1642                 case 42:
1643                         testapp_test_db_test();
1644                         break;
1645                 case 43:
1646                         testapp_test_send_cancel();
1647                         break;
1648                 case 44:
1649                         testapp_test_cancel_download_body();
1650                         break;
1651                 case 46:
1652                          testapp_test_get_mail_list_for_thread_view();
1653                         break;
1654                 case 48:
1655                         testapp_test_test_get_thread_information();
1656                         break;
1657                 case 51:
1658                         testapp_test_get_mail_list_ex();
1659                         break;
1660                 case 52:
1661                         testapp_test_get_address_info_list();
1662                         break;
1663                 case 55:
1664                         testapp_test_set_flags_field();
1665                         break;
1666                 case 56:
1667                         testapp_test_add_mail(NULL);
1668                         break;
1669                 case 57:
1670                         testapp_test_update_mail();
1671                         break;
1672                 case 58:
1673                         testapp_test_search_mail_on_server();
1674                         break;
1675                 case 59:
1676                         testapp_test_add_mail_to_search_result_box();
1677                         break;
1678                 case 60:
1679                         testapp_test_email_load_eml_file();
1680                         break;
1681                 case 0:
1682                         go_to_loop = FALSE;
1683                         break;
1684                 default:
1685                         break;
1686         }
1687
1688         return go_to_loop;
1689 }
1690
1691 void testapp_mail_main()
1692 {
1693         gboolean go_to_loop = TRUE;
1694         int menu_number = 0;
1695         int result_from_scanf = 0;
1696         
1697         while (go_to_loop) {
1698                 testapp_show_menu(EMAIL_MAIL_MENU);
1699                 testapp_show_prompt(EMAIL_MAIL_MENU);
1700                         
1701                 result_from_scanf = scanf("%d", &menu_number);
1702
1703                 go_to_loop = testapp_test_interpret_command (menu_number);
1704         }
1705 }
1706