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