4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
34 #include "email-api-account.h"
35 #include "email-api-network.h"
36 #include "email-api-mail.h"
37 #include "email-api-mailbox.h"
38 #include "email-api-etc.h"
41 #include "testapp-utility.h"
42 #include "testapp-mail.h"
43 #include "email-core-utils.h"
44 #include "email-core-mime.h"
46 #define MAIL_TEMP_BODY "/tmp/mail.txt"
49 static void testapp_test_print_sorting_menu()
51 testapp_print(" EMAIL_SORT_DATETIME_HIGH = 0\n");
52 testapp_print(" EMAIL_SORT_DATETIME_LOW = 1\n");
53 testapp_print(" EMAIL_SORT_SENDER_HIGH = 2\n");
54 testapp_print(" EMAIL_SORT_SENDER_LOW = 3\n");
55 testapp_print(" EMAIL_SORT_RCPT_HIGH = 4\n");
56 testapp_print(" EMAIL_SORT_RCPT_LOW = 5\n");
57 testapp_print(" EMAIL_SORT_SUBJECT_HIGH = 6\n");
58 testapp_print(" EMAIL_SORT_SUBJECT_LOW = 7\n");
59 testapp_print(" EMAIL_SORT_PRIORITY_HIGH = 8\n");
60 testapp_print(" EMAIL_SORT_PRIORITY_LOW = 9\n");
61 testapp_print(" EMAIL_SORT_ATTACHMENT_HIGH = 10\n");
62 testapp_print(" EMAIL_SORT_ATTACHMENT_LOW = 11\n");
63 testapp_print(" EMAIL_SORT_FAVORITE_HIGH = 12\n");
64 testapp_print(" EMAIL_SORT_FAVORITE_LOW = 13\n");
67 static void testapp_test_print_mail_list_item(email_mail_list_item_t *mail_list_item, int count)
71 testapp_print("\n>>>>> Print mail list items: count[%d]\n", count);
72 for (i=0; i< count; i++) {
73 testapp_print("\n[%d]\n", i);
74 testapp_print(" >>> Mailbox Name [ %s ] \n", mail_list_item[i].mailbox_name);
75 testapp_print(" >>> Mail ID [ %d ] \n", mail_list_item[i].mail_id);
76 testapp_print(" >>> Account ID [ %d ] \n", mail_list_item[i].account_id);
77 if ( mail_list_item[i].from!= NULL ) {
78 testapp_print(" >>> From [ %s ] \n", mail_list_item[i].from);
80 if ( mail_list_item[i].from_email_address != NULL ) {
81 testapp_print(" >>> from_email_address [ %s ] \n", mail_list_item[i].from_email_address);
83 if ( mail_list_item[i].recipients!= NULL ) {
84 testapp_print(" >>> recipients [ %s ] \n", mail_list_item[i].recipients);
86 if ( mail_list_item[i].subject != NULL ) {
87 testapp_print(" >>> subject [ %s ] \n", mail_list_item[i].subject);
89 testapp_print(" >>> text_download_yn [ %d ] \n", mail_list_item[i].is_text_downloaded);
90 testapp_print(" >>> date_time [ %d ] \n", mail_list_item[i].date_time);
91 testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list_item[i].flags_seen_field);
92 testapp_print(" >>> priority [ %d ] \n", mail_list_item[i].priority);
93 testapp_print(" >>> save_status [ %d ] \n", mail_list_item[i].save_status);
94 testapp_print(" >>> lock [ %d ] \n", mail_list_item[i].is_locked);
95 testapp_print(" >>> is_report_mail [ %d ] \n", mail_list_item[i].is_report_mail);
96 testapp_print(" >>> recipients_count [ %d ] \n", mail_list_item[i].recipients_count);
97 testapp_print(" >>> has_attachment [ %d ] \n", mail_list_item[i].has_attachment);
98 testapp_print(" >>> has_drm_attachment [ %d ] \n", mail_list_item[i].has_drm_attachment);
100 if ( mail_list_item[i].previewBodyText != NULL ) {
101 testapp_print(" >>> previewBodyText [ %s ] \n", mail_list_item[i].previewBodyText);
104 testapp_print(" >>> thread_id [ %d ] \n", mail_list_item[i].thread_id);
105 testapp_print(" >>> thread_item_count [ %d ] \n", mail_list_item[i].thread_item_count);
110 static gboolean testapp_test_add_mail (int *result_mail_id)
112 int result_from_scanf = 0;
117 int attachment_count = 0;
118 int err = EMAIL_ERROR_NONE;
120 char arg[50] = { 0 , };
121 const char *body_file_path = MAIL_TEMP_BODY;
122 email_mailbox_t *mailbox_data = NULL;
123 email_mail_data_t *test_mail_data = NULL;
124 email_attachment_data_t *attachment_data = NULL;
125 email_meeting_request_t *meeting_req = NULL;
128 testapp_print("\n > Enter account id : ");
129 result_from_scanf = scanf("%d", &account_id);
132 memset(arg, 0x00, 50);
133 testapp_print("\n > Enter mailbox id : ");
134 result_from_scanf = scanf("%d", &mailbox_id);
136 email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox_data);
138 test_mail_data = malloc(sizeof(email_mail_data_t));
139 memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
141 testapp_print("\n Sync server? [0/1]> ");
142 result_from_scanf = scanf("%d", &from_eas);
144 test_mail_data->account_id = account_id;
145 test_mail_data->save_status = 1;
146 test_mail_data->body_download_status = 1;
147 test_mail_data->flags_seen_field = 1;
148 test_mail_data->file_path_plain = strdup(body_file_path);
149 test_mail_data->mailbox_id = mailbox_id;
150 test_mail_data->mailbox_type = mailbox_data->mailbox_type;
151 test_mail_data->full_address_from = strdup("<test1@test.com>");
152 test_mail_data->full_address_to = strdup("<test2@test.com>");
153 test_mail_data->full_address_cc = strdup("<test3@test.com>");
154 test_mail_data->full_address_bcc = strdup("<test4@test.com>");
155 test_mail_data->subject = strdup("Meeting request mail");
157 body_file = fopen(body_file_path, "w");
159 testapp_print("\n body_file [%p]\n", body_file);
161 if(body_file == NULL) {
162 testapp_print("\n fopen [%s]failed\n", body_file_path);
166 for(i = 0; i < 500; i++)
167 fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
169 fprintf(body_file, "Hello world");
173 testapp_print(" > Select smime? [0: Normal, 1: sign, 2: Encrpyt, 3: sing + encrypt] : ");
174 result_from_scanf = scanf("%d", &smime_type);
175 test_mail_data->smime_type = smime_type;
177 testapp_print(" > How many file attachment? [>=0] : ");
178 result_from_scanf = scanf("%d",&attachment_count);
180 test_mail_data->attachment_count = attachment_count;
181 if ( attachment_count > 0 )
182 attachment_data = calloc(attachment_count, sizeof(email_attachment_data_t));
185 for ( i = 0; i < attachment_count ; i++ ) {
186 memset(arg, 0x00, 50);
187 testapp_print("\n > Enter attachment name : ");
188 result_from_scanf = scanf("%s", arg);
190 attachment_data[i].attachment_name = strdup(arg);
192 memset(arg, 0x00, 50);
193 testapp_print("\n > Enter attachment absolute path : ");
194 result_from_scanf = scanf("%s",arg);
196 attachment_data[i].attachment_path = strdup(arg);
197 attachment_data[i].save_status = 1;
198 attachment_data[i].mailbox_id = test_mail_data->mailbox_id;
201 testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
202 result_from_scanf = scanf("%d", &(test_mail_data->meeting_request_status));
204 if ( test_mail_data->meeting_request_status == 1
205 || test_mail_data->meeting_request_status == 2 ) {
207 /* dummy data for meeting request */
208 meeting_req = malloc(sizeof(email_meeting_request_t));
209 memset(meeting_req, 0x00, sizeof(email_meeting_request_t));
211 meeting_req->meeting_response = 1;
212 current_time = time(NULL);
213 gmtime_r(¤t_time, &(meeting_req->start_time));
214 gmtime_r(¤t_time, &(meeting_req->end_time));
215 meeting_req->location = strdup("Seoul");
216 meeting_req->global_object_id = strdup("abcdef12345");
218 meeting_req->time_zone.offset_from_GMT = 9;
219 strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
220 gmtime_r(¤t_time, &(meeting_req->time_zone.standard_time_start_date));
221 meeting_req->time_zone.standard_bias = 3;
223 strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
224 gmtime_r(¤t_time, &(meeting_req->time_zone.daylight_time_start_date));
225 meeting_req->time_zone.daylight_bias = 7;
229 if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE)
230 testapp_print("email_add_mail failed. [%d]\n", err);
232 testapp_print("email_add_mail success.\n");
234 testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
237 *result_mail_id = test_mail_data->mail_id;
240 email_free_attachment_data(&attachment_data, attachment_count);
243 email_free_meeting_request(&meeting_req, 1);
245 email_free_mail_data(&test_mail_data, 1);
246 email_free_mailbox(&mailbox_data, 1);
251 static gboolean testapp_test_update_mail()
253 int result_from_scanf = 0;
255 int err = EMAIL_ERROR_NONE;
256 int test_attachment_data_count = 0;
258 email_mail_data_t *test_mail_data = NULL;
259 email_attachment_data_t *test_attachment_data_list = NULL;
260 email_meeting_request_t *meeting_req = NULL;
262 testapp_print("\n > Enter mail id : ");
263 result_from_scanf = scanf("%d", &mail_id);
265 email_get_mail_data(mail_id, &test_mail_data);
267 testapp_print("\n > Enter Subject: ");
268 result_from_scanf = scanf("%s", arg);
270 test_mail_data->subject= strdup(arg);
272 if (test_mail_data->attachment_count > 0) {
273 if ( (err = email_get_attachment_data_list(mail_id, &test_attachment_data_list, &test_attachment_data_count)) != EMAIL_ERROR_NONE ) {
274 testapp_print("email_get_meeting_request() failed [%d]\n", err);
279 if ( test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST
280 || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE
281 || test_mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) {
283 if ( (err = email_get_meeting_request(mail_id, &meeting_req)) != EMAIL_ERROR_NONE ) {
284 testapp_print("email_get_meeting_request() failed [%d]\n", err);
288 testapp_print("\n > Enter meeting response: ");
289 result_from_scanf = scanf("%d", (int*)&(meeting_req->meeting_response));
292 if ( (err = email_update_mail(test_mail_data, test_attachment_data_list, test_attachment_data_count, meeting_req, 0)) != EMAIL_ERROR_NONE)
293 testapp_print("email_update_mail failed.[%d]\n", err);
295 testapp_print("email_update_mail success\n");
298 email_free_mail_data(&test_mail_data, 1);
300 if(test_attachment_data_list)
301 email_free_attachment_data(&test_attachment_data_list, test_attachment_data_count);
304 email_free_meeting_request(&meeting_req, 1);
309 static gboolean testapp_test_get_mails()
311 testapp_print("\n >>> testapp_test_get_mails : Entered \n");
312 email_mail_data_t *mails = NULL, **mails_pointer = NULL;
314 int count = 0, i = 0;
319 int err_code = EMAIL_ERROR_NONE;
320 int to_get_count = 0;
321 int is_for_thread_view = 0;
323 int result_from_scanf = 0;
324 struct tm *temp_time_info;
326 testapp_print("\n > Enter Account_id (0 = all accounts) : ");
327 result_from_scanf = scanf("%d",&account_id);
329 testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :");
330 result_from_scanf = scanf("%d", &mailbox_id);
332 testapp_print("\n > Enter Sorting : ");
333 result_from_scanf = scanf("%d",&sorting);
335 testapp_print("\n > Enter Start index (starting at 0): ");
336 result_from_scanf = scanf("%d",&start_index);
338 testapp_print("\n > Enter max_count : ");
339 result_from_scanf = scanf("%d",&limit_count);
341 testapp_print("\n > For thread view : ");
342 result_from_scanf = scanf("%d",&is_for_thread_view);
344 testapp_print("\n > Mail count only (0:list 1:count): ");
345 result_from_scanf = scanf("%d",&to_get_count);
348 mails_pointer = NULL;
350 mails_pointer = &mails;
352 if(is_for_thread_view == -2) {
353 list_type = EMAIL_LIST_TYPE_LOCAL;
355 else if(is_for_thread_view == -1)
356 list_type = EMAIL_LIST_TYPE_THREAD;
358 list_type = EMAIL_LIST_TYPE_NORMAL;
361 if(mailbox_id == 0) {
362 testapp_print("Calling email_get_mail_list for all mailbox.\n");
363 err_code = email_get_mails(account_id, 0, list_type, start_index, limit_count, sorting, mails_pointer, &count);
365 testapp_print("email_get_mails failed - err[%d]\n", err_code);
368 testapp_print("Calling email_get_mail_list for %d mailbox_id.\n", mailbox_id);
369 err_code = email_get_mails(account_id, mailbox_id, list_type, start_index, limit_count, sorting, mails_pointer, &count);
371 testapp_print("email_get_mails failed - err[%d]\n", err_code);
373 testapp_print("email_get_mails >>>>>>count - %d\n",count);
376 for (i=0; i< count; i++) {
377 testapp_print("\n[%d]\n", i);
378 testapp_print(" >>> mailbox_id [ %d ] \n", mails[i].mailbox_id);
379 testapp_print(" >>> mail_id [ %d ] \n", mails[i].mail_id);
380 testapp_print(" >>> account_id [ %d ] \n", mails[i].account_id);
381 if ( mails[i].full_address_from != NULL )
382 testapp_print(" >>> full_address_from [ %s ] \n", mails[i].full_address_from);
383 if ( mails[i].full_address_to != NULL )
384 testapp_print(" >>> recipients [ %s ] \n", mails[i].full_address_to);
385 if ( mails[i].subject != NULL )
386 testapp_print(" >>> subject [ %s ] \n", mails[i].subject);
387 testapp_print(" >>> body_download_status [ %d ] \n", mails[i].body_download_status);
388 temp_time_info = localtime(&mails[i].date_time);
389 testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
390 temp_time_info->tm_year + 1900,
391 temp_time_info->tm_mon+1,
392 temp_time_info->tm_mday,
393 temp_time_info->tm_hour,
394 temp_time_info->tm_min,
395 temp_time_info->tm_sec);
396 testapp_print(" >>> flags_seen_field [ %d ] \n", mails[i].flags_seen_field);
397 testapp_print(" >>> priority [ %d ] \n", mails[i].priority);
398 testapp_print(" >>> save_status [ %d ] \n", mails[i].save_status);
399 testapp_print(" >>> lock_status [ %d ] \n", mails[i].lock_status);
400 testapp_print(" >>> attachment_count [ %d ] \n", mails[i].attachment_count);
401 if ( mails[i].preview_text != NULL )
402 testapp_print(" >>> previewBodyText [ %s ] \n", mails[i].preview_text);
407 testapp_print(" >>> testapp_test_get_mails : End \n");
411 #define TEMP_ARGUMENT_SIZE 4096
413 static gboolean testapp_test_mail_send (int *result_mail_id)
415 int added_mail_id = 0;
416 int err = EMAIL_ERROR_NONE;
418 email_option_t option = { 0 };
419 email_mailbox_t mailbox_data = { 0 };
420 email_mail_data_t *result_mail_data = NULL;
422 testapp_test_add_mail(&added_mail_id);
425 email_get_mail_data(added_mail_id, &result_mail_data);
427 memset(&mailbox_data, 0x00, sizeof(email_mailbox_t));
428 mailbox_data.account_id = result_mail_data->account_id;
429 mailbox_data.mailbox_id = result_mail_data->mailbox_id;
430 option.keep_local_copy = 1;
432 testapp_print("Calling email_send_mail...\n");
434 if( email_send_mail(added_mail_id, &option, &handle) < 0) {
435 testapp_print("Sending failed[%d]\n", err);
438 testapp_print("Start sending. handle[%d]\n", handle);
441 email_free_mail_data(&result_mail_data, 1);
445 *result_mail_id = added_mail_id;
450 static gboolean testapp_test_get_mail_list()
452 email_list_filter_t *filter_list = NULL;
453 email_list_sorting_rule_t *sorting_rule_list = NULL;
454 email_mail_list_item_t *result_mail_list = NULL;
455 int result_mail_count = 0;
456 int err = EMAIL_ERROR_NONE;
459 filter_list = malloc(sizeof(email_list_filter_t) * 9);
460 memset(filter_list, 0 , sizeof(email_list_filter_t) * 9);
462 filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
463 filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
464 filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
465 filter_list[0].list_filter_item.rule.key_value.string_type_value = strdup("RE");
466 filter_list[0].list_filter_item.rule.case_sensitivity = false;
468 filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
469 filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
471 filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
472 filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO;
473 filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
474 filter_list[2].list_filter_item.rule.key_value.string_type_value = strdup("RE");
475 filter_list[2].list_filter_item.rule.case_sensitivity = false;
477 filter_list[3].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
478 filter_list[3].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
480 filter_list[4].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
481 filter_list[4].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_CC;
482 filter_list[4].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
483 filter_list[4].list_filter_item.rule.key_value.string_type_value = strdup("RE");
484 filter_list[4].list_filter_item.rule.case_sensitivity = false;
486 filter_list[5].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
487 filter_list[5].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
489 filter_list[6].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
490 filter_list[6].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_BCC;
491 filter_list[6].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
492 filter_list[6].list_filter_item.rule.key_value.string_type_value = strdup("RE");
493 filter_list[6].list_filter_item.rule.case_sensitivity = false;
495 filter_list[7].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
496 filter_list[7].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
498 filter_list[8].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
499 filter_list[8].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_FROM;
500 filter_list[8].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
501 filter_list[8].list_filter_item.rule.key_value.string_type_value = strdup("RE");
502 filter_list[8].list_filter_item.rule.case_sensitivity = false;
505 filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
506 filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_ACCOUNT_ID;
507 filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
508 filter_list[0].list_filter_item.rule.key_value.integer_type_value = 1;
510 filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
511 filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_AND;
513 filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
514 filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_MAILBOX_NAME;
515 filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_EQUAL;
516 filter_list[2].list_filter_item.rule.key_value.string_type_value = strdup("INBOX");
517 filter_list[2].list_filter_item.rule.case_sensitivity = true;
520 sorting_rule_list = malloc(sizeof(email_list_sorting_rule_t) * 2);
521 memset(sorting_rule_list, 0 , sizeof(email_list_sorting_rule_t) * 2);
523 sorting_rule_list[0].target_attribute = EMAIL_MAIL_ATTRIBUTE_ATTACHMENT_COUNT;
524 sorting_rule_list[0].sort_order = EMAIL_SORT_ORDER_ASCEND;
525 sorting_rule_list[0].force_boolean_check = true;
527 sorting_rule_list[1].target_attribute = EMAIL_MAIL_ATTRIBUTE_DATE_TIME;
528 sorting_rule_list[1].sort_order = EMAIL_SORT_ORDER_ASCEND;
530 err = email_get_mail_list_ex(filter_list, 9, sorting_rule_list, 2, -1, -1, &result_mail_list, &result_mail_count);
532 if(err == EMAIL_ERROR_NONE) {
533 testapp_print("email_get_mail_list_ex succeed.\n");
535 for(i = 0; i < result_mail_count; i++) {
536 testapp_print("mail_id [%d], subject [%s], from [%s]\n", result_mail_list[i].mail_id, result_mail_list[i].subject, result_mail_list[i].from);
540 testapp_print("email_get_mail_list_ex failed.\n");
543 email_free_list_filter(&filter_list, 9);
548 static gboolean testapp_test_send_cancel ()
554 int *mailIdList = NULL;
556 int result_from_scanf = 0;
558 testapp_print("\n > Enter total Number of mail want to send: ");
559 result_from_scanf = scanf("%d", &num);
560 mailIdList = (int *)malloc(sizeof(int)*num);
564 for(i = 1;i <=num ; i++) {
565 testapp_test_mail_send(&mail_id);
567 testapp_print("mail_id[%d]",mail_id);
569 mailIdList[i] = mail_id;
570 testapp_print("mailIdList[%d][%d]",i,mailIdList[i]);
573 testapp_print("\n > Do you want to cancel the send mail job '1' or '0': ");
574 result_from_scanf = scanf("%d", &Y);
576 testapp_print("\n >Enter mail-id[1-%d] ",i);
577 result_from_scanf = scanf("%d", &j);
578 testapp_print("\n mailIdList[%d] ",mailIdList[j]);
579 if(email_cancel_sending_mail( mailIdList[j]) < 0)
580 testapp_print("email_cancel_sending_mail failed..!");
582 testapp_print("email_cancel_sending_mail success..!");
588 static gboolean testapp_test_delete()
590 int mail_id=0, account_id =0;
592 int err = EMAIL_ERROR_NONE;
594 int result_from_scanf = 0;
596 testapp_print("\n > Enter Account_id: ");
597 result_from_scanf = scanf("%d", &account_id);
599 testapp_print("\n > Enter Mail_id: ");
600 result_from_scanf = scanf("%d", &mail_id);
602 testapp_print("\n > Enter Mailbox id: ");
603 result_from_scanf = scanf("%d", &mailbox_id);
605 testapp_print("\n > Enter from_server: ");
606 result_from_scanf = scanf("%d", &from_server);
609 if( (err = email_delete_mail(mailbox_id, &mail_id, 1, from_server)) < 0)
610 testapp_print("\n email_delete_mail failed[%d]\n", err);
612 testapp_print("\n email_delete_mail success\n");
619 static gboolean testapp_test_move()
624 int result_from_scanf = 0;
626 for(i = 0; i< 3; i++) {
627 testapp_print("\n > Enter mail_id: ");
628 result_from_scanf = scanf("%d",&mail_id[i]);
631 testapp_print("\n > Enter mailbox_id: ");
632 result_from_scanf = scanf("%d", &mailbox_id);
635 email_move_mail_to_mailbox(mail_id, 3, mailbox_id);
639 static gboolean testapp_test_delete_all()
642 int err = EMAIL_ERROR_NONE;
643 int result_from_scanf = 0;
645 testapp_print("\n > Enter mailbox_id: ");
646 result_from_scanf = scanf("%d",&mailbox_id);
648 /* delete all message */
649 if ( (err = email_delete_all_mails_in_mailbox(mailbox_id, 0)) < 0)
650 testapp_print("email_delete_all_mails_in_mailbox failed [%d]\n", err);
652 testapp_print("email_delete_all_mails_in_mailbox Success\n");
658 static gboolean testapp_test_add_attachment()
661 int result_from_scanf = 0;
663 email_attachment_data_t attachment;
665 testapp_print("\n > Enter Mail Id: ");
666 result_from_scanf = scanf("%d", &mail_id);
668 memset(&attachment, 0x00, sizeof(email_attachment_data_t));
669 memset(arg, 0x00, 100);
670 testapp_print("\n > Enter attachment name: ");
671 result_from_scanf = scanf("%s",arg);
673 attachment.attachment_name = strdup(arg);
675 memset(arg, 0x00, 100);
676 testapp_print("\n > Enter attachment absolute path: ");
677 result_from_scanf = scanf("%s",arg);
679 attachment.save_status = true;
680 attachment.attachment_path = strdup(arg);
681 if(email_add_attachment(mail_id, &attachment) < 0)
682 testapp_print("email_add_attachment failed\n");
684 testapp_print("email_add_attachment success\n");
691 static gboolean testapp_test_set_deleted_flag()
695 int mail_ids[100] = { 0, };
696 int temp_mail_id = 0;
697 int err_code = EMAIL_ERROR_NONE;
698 int result_from_scanf = 0;
700 testapp_print("\n >>> Input target account id: ");
701 result_from_scanf = scanf("%d", &account_id);
704 testapp_print("\n >>> Input target mail id ( Input 0 to terminate ) [MAX = 100]: ");
705 result_from_scanf = scanf("%d", &temp_mail_id);
706 mail_ids[index++] = temp_mail_id;
707 } while (temp_mail_id != 0);
709 err_code = email_set_flags_field(account_id, mail_ids, index, EMAIL_FLAGS_DELETED_FIELD, 1, true);
710 testapp_print("email_set_flags_field returns - err[%d]\n", err_code);
715 static gboolean testapp_test_expunge_mails_deleted_flagged()
719 int err_code = EMAIL_ERROR_NONE;
721 int result_from_scanf = 0;
723 testapp_print("\n >>> Input target mailbox id: ");
724 result_from_scanf = scanf("%d", &mailbox_id);
726 testapp_print("\n >>> Expunge on server?: ");
727 result_from_scanf = scanf("%d", &on_server);
729 err_code = email_expunge_mails_deleted_flagged(mailbox_id, on_server, &handle);
731 testapp_print("email_expunge_mails_deleted_flagged returns - err[%d]\n", err_code);
736 static gboolean testapp_test_get_mail_list_ex()
738 testapp_print("\n >>> testapp_test_get_mail_list_ex : Entered \n");
739 email_mail_list_item_t *mail_list = NULL, **mail_list_pointer = NULL;
741 int count = 0, i = 0;
746 int err_code = EMAIL_ERROR_NONE;
747 int to_get_count = 0;
748 int is_for_thread_view = 0;
750 struct tm *temp_time_info;
751 int result_from_scanf = 0;
753 testapp_print("\n > Enter Account_id (0 = all accounts) : ");
754 result_from_scanf = scanf("%d",&account_id);
756 testapp_print("\n > Enter Mailbox id (0 = all mailboxes) :");
757 result_from_scanf = scanf("%d", &mailbox_id);
759 testapp_print("\n > Enter Sorting : ");
760 result_from_scanf = scanf("%d",&sorting);
762 testapp_print("\n > Enter Start index (starting at 0): ");
763 result_from_scanf = scanf("%d",&start_index);
765 testapp_print("\n > Enter max_count : ");
766 result_from_scanf = scanf("%d",&limit_count);
768 testapp_print("\n > For thread view : ");
769 result_from_scanf = scanf("%d",&is_for_thread_view);
771 testapp_print("\n > Count mails?(1: YES):");
772 result_from_scanf = scanf("%d",&to_get_count);
775 mail_list_pointer = NULL;
777 mail_list_pointer = &mail_list;
779 if(is_for_thread_view == -2) {
780 list_type = EMAIL_LIST_TYPE_LOCAL;
782 else if(is_for_thread_view == -1)
783 list_type = EMAIL_LIST_TYPE_THREAD;
785 list_type = EMAIL_LIST_TYPE_NORMAL;
788 if( mailbox_id == 0) {
789 testapp_print("Calling email_get_mail_list for all mailbox.\n");
790 err_code = email_get_mail_list(account_id, 0, list_type, start_index, limit_count, sorting, mail_list_pointer, &count);
792 testapp_print("email_get_mail_list failed - err[%d]\n", err_code);
795 testapp_print("Calling email_get_mail_list for %d mailbox_id.\n", mailbox_id);
796 err_code = email_get_mail_list(account_id, mailbox_id, list_type, start_index, limit_count, sorting, mail_list_pointer, &count);
798 testapp_print("email_get_mail_list failed - err[%d]\n", err_code);
800 testapp_print("email_get_mail_list >>>>>>count - %d\n",count);
803 for (i=0; i< count; i++) {
804 testapp_print("\n[%d]\n", i);
805 testapp_print(" >>> mailbox_id [ %d ] \n", mail_list[i].mailbox_id);
806 testapp_print(" >>> mail_id [ %d ] \n", mail_list[i].mail_id);
807 testapp_print(" >>> account_id [ %d ] \n", mail_list[i].account_id);
808 if ( mail_list[i].from != NULL )
809 testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
810 if ( mail_list[i].recipients != NULL )
811 testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
812 if ( mail_list[i].subject != NULL )
813 testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
814 testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
815 temp_time_info = localtime(&mail_list[i].date_time);
816 testapp_print(" >>> date_time [ %d/%d/%d %d:%d:%d] \n",
817 temp_time_info->tm_year + 1900,
818 temp_time_info->tm_mon+1,
819 temp_time_info->tm_mday,
820 temp_time_info->tm_hour,
821 temp_time_info->tm_min,
822 temp_time_info->tm_sec);
823 testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
824 testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
825 testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
826 testapp_print(" >>> is_locked [ %d ] \n", mail_list[i].is_locked);
827 testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
828 if ( mail_list[i].previewBodyText != NULL )
829 testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
834 testapp_print("\n >>> email_get_mail_list : End \n");
839 static gboolean testapp_test_get_mail_list_for_thread_view()
841 testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : Entered \n");
842 email_mail_list_item_t *mail_list = NULL;
843 int count = 0, i = 0;
845 int err_code = EMAIL_ERROR_NONE;
846 struct tm *time_info;
849 if ( email_get_mail_list(account_id, 0 , EMAIL_LIST_TYPE_THREAD, 0, 500, EMAIL_SORT_DATETIME_HIGH, &mail_list, &count) < 0) {
850 testapp_print("email_get_mail_list failed : %d\n",err_code);
853 testapp_print("email_get_mail_list >>>>>>count - %d\n",count);
855 for (i=0; i< count; i++) {
856 testapp_print(" i [%d]\n", i);
857 testapp_print(" >>> Mail ID [ %d ] \n", mail_list[i].mail_id);
858 testapp_print(" >>> Account ID [ %d ] \n", mail_list[i].account_id);
859 testapp_print(" >>> Mailbox id [ %d ] \n", mail_list[i].mailbox_id);
860 testapp_print(" >>> From [ %s ] \n", mail_list[i].from);
861 testapp_print(" >>> recipients [ %s ] \n", mail_list[i].recipients);
862 testapp_print(" >>> subject [ %s ] \n", mail_list[i].subject);
863 testapp_print(" >>> is_text_downloaded [ %d ] \n", mail_list[i].is_text_downloaded);
864 time_info = localtime(&mail_list[i].date_time);
865 testapp_print(" >>> date_time [ %s ] \n", asctime(time_info));
866 testapp_print(" >>> flags_seen_field [ %d ] \n", mail_list[i].flags_seen_field);
867 testapp_print(" >>> priority [ %d ] \n", mail_list[i].priority);
868 testapp_print(" >>> save_status [ %d ] \n", mail_list[i].save_status);
869 testapp_print(" >>> lock [ %d ] \n", mail_list[i].is_locked);
870 testapp_print(" >>> has_attachment [ %d ] \n", mail_list[i].has_attachment);
871 testapp_print(" >>> previewBodyText [ %s ] \n", mail_list[i].previewBodyText);
872 testapp_print(" >>> thread_id [ %d ] \n", mail_list[i].thread_id);
873 testapp_print(" >>> thread__item_count [ %d ] \n", mail_list[i].thread_item_count);
877 testapp_print(" >>> testapp_test_get_mail_list_for_thread_view : End \n");
881 static gboolean testapp_test_count ()
885 email_list_filter_t *filter_list = NULL;
887 filter_list = malloc(sizeof(email_list_filter_t) * 3);
888 memset(filter_list, 0 , sizeof(email_list_filter_t) * 3);
890 filter_list[0].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
891 filter_list[0].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_SUBJECT;
892 filter_list[0].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
893 filter_list[0].list_filter_item.rule.key_value.string_type_value = strdup("RE");
894 filter_list[0].list_filter_item.rule.case_sensitivity = false;
896 filter_list[1].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_OPERATOR;
897 filter_list[1].list_filter_item.operator_type = EMAIL_LIST_FILTER_OPERATOR_OR;
899 filter_list[2].list_filter_item_type = EMAIL_LIST_FILTER_ITEM_RULE;
900 filter_list[2].list_filter_item.rule.target_attribute = EMAIL_MAIL_ATTRIBUTE_TO;
901 filter_list[2].list_filter_item.rule.rule_type = EMAIL_LIST_FILTER_RULE_INCLUDE;
902 filter_list[2].list_filter_item.rule.key_value.string_type_value = strdup("RE");
903 filter_list[2].list_filter_item.rule.case_sensitivity = false;
905 if(EMAIL_ERROR_NONE == email_count_mail(filter_list, 3, &total, &unseen))
906 printf("\n Total: %d, Unseen: %d \n", total, unseen);
910 static gboolean testapp_test_set_flags_field ()
914 int result_from_scanf = 0;
916 testapp_print("\n > Enter Account ID: ");
917 result_from_scanf = scanf("%d", &account_id);
919 testapp_print("\n > Enter Mail ID: ");
920 result_from_scanf = scanf("%d", &mail_id);
922 if(email_set_flags_field(account_id, &mail_id, 1, EMAIL_FLAGS_FLAGGED_FIELD, 1, 1) < 0)
923 testapp_print("email_set_flags_field failed");
925 testapp_print("email_set_flags_field success");
930 static gboolean testapp_test_download_body ()
933 unsigned handle = 0, err;
934 int result_from_scanf = 0;
936 testapp_print("\n > Enter Mail Id: ");
937 result_from_scanf = scanf("%d", &mail_id);
938 err = email_download_body(mail_id, 0, &handle);
940 testapp_print("email_download_body failed");
942 testapp_print("email_download_body success");
943 testapp_print("handle[%d]\n", handle);
949 static gboolean testapp_test_cancel_download_body ()
955 int result_from_scanf = 0;
957 email_mailbox_t mailbox;
958 memset(&mailbox, 0x00, sizeof(email_mailbox_t));
960 testapp_print("\n > Enter account_id: ");
961 result_from_scanf = scanf("%d", &account_id);
963 testapp_print("\n > Enter mail id: ");
964 result_from_scanf = scanf("%d", &mail_id);
966 if( email_download_body(mail_id, 0, &handle) < 0)
967 testapp_print("email_download_body failed");
969 testapp_print("email_download_body success\n");
970 testapp_print("Do u want to cancel download job>>>>>1/0\n");
971 result_from_scanf = scanf("%d",&yes);
973 if(email_cancel_job(account_id, handle , EMAIL_CANCELED_BY_USER) < 0)
974 testapp_print("email_cancel_job failed..!");
976 testapp_print("email_cancel_job success..!");
977 testapp_print("handle[%d]\n", handle);
984 static gboolean testapp_test_download_attachment ()
987 int attachment_no = 0;
989 int result_from_scanf = 0;
991 testapp_print("\n > Enter Mail Id: ");
992 result_from_scanf = scanf("%d", &mail_id);
994 testapp_print("\n > Enter attachment number: ");
995 result_from_scanf = scanf("%d", &attachment_no);
997 if( email_download_attachment(mail_id, attachment_no ,&handle) < 0)
998 testapp_print("email_download_attachment failed");
1000 testapp_print("email_download_attachment success");
1001 testapp_print("handle[%d]\n", handle);
1007 static gboolean testapp_test_retry_send()
1011 int result_from_scanf = 0;
1013 email_mailbox_t mailbox;
1014 memset(&mailbox, 0x00, sizeof(email_mailbox_t));
1016 testapp_print("\n > Enter Mail Id: ");
1017 result_from_scanf = scanf("%d", &mail_id);
1019 testapp_print("\n > Enter timeout in seconds: ");
1020 result_from_scanf = scanf("%d", &timeout);
1022 if( email_retry_sending_mail(mail_id, timeout) < 0)
1023 testapp_print("email_retry_sending_mail failed");
1027 static gboolean testapp_test_move_all_mails_to_mailbox()
1029 int err = EMAIL_ERROR_NONE;
1030 int result_from_scanf = 0;
1032 int dest_mailbox_id;
1034 testapp_print("src mailbox id> ");
1035 result_from_scanf = scanf("%d", &src_mailbox_id);
1037 testapp_print("dest mailbox id> ");
1038 result_from_scanf = scanf("%d", &dest_mailbox_id);
1040 err = email_move_all_mails_to_mailbox(src_mailbox_id, dest_mailbox_id);
1042 testapp_print("email_move_all_mails_to_mailbox failed: err[%d]\n", err);
1045 testapp_print("email_move_all_mails_to_mailbox suceeded\n");
1051 static gboolean testapp_test_get_totaldiskusage()
1053 unsigned long total_size = 0;
1054 int err_code = EMAIL_ERROR_NONE ;
1056 err_code = email_get_disk_space_usage(&total_size);
1058 testapp_print("email_get_disk_space_usage failed err : %d\n",err_code);
1060 testapp_print("email_get_disk_space_usage SUCCESS, total disk usage in KB : %ld \n", total_size);
1067 static gboolean testapp_test_db_test()
1069 int err = EMAIL_ERROR_NONE;
1070 int result_from_scanf = 0;
1077 to = (char *) malloc(500000);
1078 cc = (char *) malloc(500000);
1079 bcc = (char *) malloc(500000);
1081 memset(to, 0x00, sizeof(to));
1082 memset(cc, 0x00, sizeof(to));
1083 memset(bcc, 0x00, sizeof(to));
1085 testapp_print("Input Mail id:\n");
1086 result_from_scanf = scanf("%d", &mail_id);
1087 testapp_print("Input Account id:\n");
1088 result_from_scanf = scanf("%d", &account_id);
1089 testapp_print("Input TO field:\n");
1090 result_from_scanf = scanf("%s", to);
1091 testapp_print("Input CC field:\n");
1092 result_from_scanf = scanf("%s", cc);
1093 testapp_print("Input BCC field:\n");
1094 result_from_scanf = scanf("%s", bcc);
1096 if ( emstorage_test(mail_id, account_id, to, cc, bcc, &err) == true ) {
1097 testapp_print(">> Saving Succeeded\n");
1100 testapp_print(">> Saving Failed[%d]\n", err);
1110 static gboolean testapp_test_address_format_check_test()
1117 int err = EMAIL_ERROR_NONE;
1118 char *pAddress = NULL;
1119 char input_address[8096];
1120 char *address_list[] = {
1123 "tom@gmail.com@gmail.com",
1125 "\"Tom\"<tom@gmail.com>",
1126 "\"Tom\"[tom@gmail.com]",
1127 "\"Tom\"<tom,@gmail.com>",
1131 "<tom@gmail.com>,tom@gmail.com",
1132 "<tom@gmail.com>;tom@gmail.com",
1141 "\"\"Tom\"<tom,@gmail.com>",
1142 "tom@gmail.com,tom@gmail.com",
1144 "<tom@gmail.com>,tom@.gmail.com",
1145 "&& tom@live.com ----",
1146 "madhu <tom@gmail.com>",
1147 "tom@gmail.com, && tom@live.com",
1148 "tom@gmail.com , && tom@live.com",
1149 "< tom@gmail.com > , < tom@.gmail.com >",
1150 "tom@gmail.com , tom@gmail.com",
1152 "<to m@gmail.com >",
1153 "<tom@gmail.com>;tom@gmail.com",
1154 "Tom< tom@gmail.com > , Tom <tom@gmail.com>",
1155 " \"Tom\" < tom@gmail.com> , \"Tom\" < tom@gmail.com> , Tom < tom@gmail.com> ; Tom < tom@gmail.com>,\"tomtom\" < tom@aol.com>,\"tomtom\" < tom@aol.com> ,\"tomtom\" <tom@aol.com>;<tom@live.com>, <tom@live.com>; \"tomtomtomtom\" <tom@live.com> ; \"tomtomtomtom\" <tom@live.com>,\"Tom\" < tom@gmail.com>",
1156 "<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>,<tom@gmail.com>",
1157 " tom@gmail.com ; < tom@gmail.com > ",
1158 "\"Tom\" < tom@gmail.com > ; mama < tom@gmail.com > , abcd@gmail.com , abc@gmail.com ,\"tomtom\" <tom@aol.com>,\"tomtom\" < tom@aol.com> ;\"tomtom\" < tom@aol.com > ,\"tomtom\" <tom@aol.com> , \"tomtomtomtom\" <tom@live.com> ",
1159 " \"tomtom\" <tom@aol.com> ;\"tomtom\" <tom@aol.com> ; ",
1160 " tom@gmail.com , tom@gmail.com , tom@gmail.com; Tom < tom@gmail.com > ,< tom@aol.com>, <tom@aol.com> ,<tom@aol.com>;<tom@live.com>, tom@live.com;tom@live.com; \"tomtomtomtom\" <tom@live.com>,\"Tom\" < tom@gmail.com> ; ",
1161 "<tom@aol.com> , \"tomtomtomtom\" <tom@live.com>,\"Tom\" < tom@gmail.com> ; ",
1162 " Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom < tom@gmail.com> ,<tom@gmail.com>,Tom <tom@gmail.com >,Tom< tom@gmail.com > , Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>,Tom <tom@gmail.com>",
1165 int address_count = 0;
1167 testapp_print("Select input method:\n");
1168 testapp_print("1. Test data\n");
1169 testapp_print("2. Keyboard\n");
1170 result_from_scanf = scanf("%d", &type);
1175 for ( i = 0; address_list[i] != NULL; i++ ) {
1176 testapp_print("[%d] addr[%s]\n", i, address_list[i]);
1179 testapp_print("Choose address to be tested:[99:quit]\n");
1180 result_from_scanf = scanf("%d", &index);
1184 testapp_print(">> [%d] Checking? (1:Yes, Other:No) [%s]\n", index, address_list[index]);
1185 result_from_scanf = scanf("%d", &check_yn);
1186 if ( check_yn == 1 ) {
1187 pAddress = strdup(address_list[index]);
1188 if ( em_verify_email_address(pAddress, false, &err ) == true ) {
1189 testapp_print("<< [%d] Checking Succeeded : addr[%s]\n", index, address_list[index]);
1192 testapp_print("<< [%d] Checking Failed : addr[%s], err[%d]\n", index, address_list[index], err);
1200 testapp_print("<< [%d] Skipped : addr[%s]\n", index, address_list[index]);
1206 testapp_print("Input address: \n");
1207 result_from_scanf = scanf("%s", input_address);
1208 if ( em_verify_email_address(input_address, false, &err ) == true ) {
1209 testapp_print(">> Saving Succeeded : addr[%s]\n", input_address);
1212 testapp_print(">> Saving Failed : addr[%s], err[%d]\n", input_address, err);
1216 testapp_print("wrong nuber... [%d]\n", type);
1223 static gboolean testapp_test_get_max_mail_count()
1226 int err = EMAIL_ERROR_NONE;
1228 err = email_get_max_mail_count(&max_count);
1229 testapp_print("\n\t>>>>> email_get_max_mail_count() return [%d]\n\n", max_count);
1234 #include "email-storage.h"
1235 static gboolean testapp_test_test_get_thread_information()
1237 int error_code, thread_id= 38;
1238 email_mail_list_item_t *result_mail;
1240 if( (error_code = email_get_thread_information_ex(thread_id, &result_mail)) == EMAIL_ERROR_NONE) {
1241 testapp_print("email_get_thread_information returns = %d\n", error_code);
1242 testapp_print("subject = %s\n", result_mail->subject);
1243 testapp_print("mail_id = %d\n", result_mail->mail_id);
1244 testapp_print("from = %s\n", result_mail->from);
1245 testapp_print("thrad_id = %d\n", result_mail->thread_id);
1246 testapp_print("count = %d\n", result_mail->thread_item_count);
1252 static gboolean testapp_test_get_address_info_list()
1254 testapp_print(" >>> testapp_test_get_address_info_list : Entered \n");
1259 int result_from_scanf = 0;
1260 email_address_info_list_t *address_info_list= NULL;
1261 email_address_info_t *p_address_info = NULL;
1265 memset(buf, 0x00, sizeof(buf));
1266 testapp_print("\n > Enter mail_id: ");
1267 result_from_scanf = scanf("%d",&mail_id);
1269 email_get_address_info_list(mail_id, &address_info_list);
1271 testapp_print("===================================================\n");
1272 testapp_print("\t\t\t address info list\n");
1273 testapp_print("===================================================\n");
1274 testapp_print("address_type\t address \t\tdisplay_name\t contact id\n");
1275 testapp_print("===================================================\n");
1277 for ( i = EMAIL_ADDRESS_TYPE_FROM; i <= EMAIL_ADDRESS_TYPE_BCC; i++ ) {
1279 case EMAIL_ADDRESS_TYPE_FROM:
1280 list = address_info_list->from;
1282 case EMAIL_ADDRESS_TYPE_TO:
1283 list = address_info_list->to;
1285 case EMAIL_ADDRESS_TYPE_CC:
1286 list = address_info_list->cc;
1288 case EMAIL_ADDRESS_TYPE_BCC:
1289 list = address_info_list->bcc;
1293 /* delete dynamic-allocated memory for each item */
1294 node = g_list_first(list);
1295 while ( node != NULL ) {
1296 p_address_info = (email_address_info_t*)node->data;
1297 testapp_print("%d\t\t%s\t%s\t%d\n", p_address_info->address_type, p_address_info->address, p_address_info->display_name, p_address_info->contact_id);
1299 node = g_list_next(node);
1301 testapp_print("\n");
1303 testapp_print("===================================================\n");
1305 if(address_info_list)
1306 email_free_address_info_list(&address_info_list);
1308 testapp_print(" >>> testapp_test_get_address_info_list : END \n");
1312 static gboolean testapp_test_search_mail_on_server()
1314 testapp_print(" >>> testapp_test_search_mail_on_server : Entered \n");
1316 int err_code = EMAIL_ERROR_NONE;
1319 int search_key_value_integer = 0;
1320 int result_from_scanf = 0;
1321 email_search_filter_type search_filter_type = 0;
1322 email_search_filter_t search_filter;
1323 unsigned int handle = 0;
1324 char search_key_value_string[MAX_EMAIL_ADDRESS_LENGTH];
1326 testapp_print("input account id : ");
1327 result_from_scanf = scanf("%d",&account_id);
1329 testapp_print("input mailbox id : ");
1330 result_from_scanf = scanf("%d", &mailbox_id);
1333 " EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO = 1, ( integet type ) \n"
1334 " EMAIL_SEARCH_FILTER_TYPE_UID = 2, ( integet type ) \n"
1335 " EMAIL_SEARCH_FILTER_TYPE_BCC = 7, ( string type ) \n"
1336 " EMAIL_SEARCH_FILTER_TYPE_CC = 9, ( string type ) \n"
1337 " EMAIL_SEARCH_FILTER_TYPE_FROM = 10, ( string type ) \n"
1338 " EMAIL_SEARCH_FILTER_TYPE_KEYWORD = 11, ( string type ) \n"
1339 " EMAIL_SEARCH_FILTER_TYPE_SUBJECT = 13, ( string type ) \n"
1340 " EMAIL_SEARCH_FILTER_TYPE_TO = 15, ( string type ) \n"
1341 " EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER = 16, ( integet type ) \n"
1342 " EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER = 17, ( integet type ) \n"
1343 " EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE = 20, ( time type ) \n"
1344 " EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON = 21, ( time type ) \n"
1345 " EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE = 22, ( time type ) \n"
1346 " EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED = 26, ( integet type ) \n"
1347 " EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED = 28, ( integet type ) \n"
1348 " EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT = 30, ( integet type ) \n"
1349 " EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED = 32, ( integet type ) \n"
1350 " EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT = 34, ( integet type ) \n"
1351 " EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN = 36, ( integet type ) \n"
1352 " EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID = 43, ( string type ) \n");
1353 testapp_print("input search filter type : ");
1354 result_from_scanf = scanf("%d", (int*)&search_filter_type);
1356 search_filter.search_filter_type = search_filter_type;
1358 switch(search_filter_type) {
1359 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_NO :
1360 case EMAIL_SEARCH_FILTER_TYPE_UID :
1361 case EMAIL_SEARCH_FILTER_TYPE_SIZE_LARSER :
1362 case EMAIL_SEARCH_FILTER_TYPE_SIZE_SMALLER :
1363 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_ANSWERED :
1364 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DELETED :
1365 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_DRAFT :
1366 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_FLAGED :
1367 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_RECENT :
1368 case EMAIL_SEARCH_FILTER_TYPE_FLAGS_SEEN :
1369 testapp_print("input search filter key value : ");
1370 result_from_scanf = scanf("%d", &search_key_value_integer);
1371 search_filter.search_filter_key_value.integer_type_key_value = search_key_value_integer;
1374 case EMAIL_SEARCH_FILTER_TYPE_BCC :
1375 case EMAIL_SEARCH_FILTER_TYPE_CC :
1376 case EMAIL_SEARCH_FILTER_TYPE_FROM :
1377 case EMAIL_SEARCH_FILTER_TYPE_KEYWORD :
1378 case EMAIL_SEARCH_FILTER_TYPE_SUBJECT :
1379 case EMAIL_SEARCH_FILTER_TYPE_TO :
1380 case EMAIL_SEARCH_FILTER_TYPE_MESSAGE_ID :
1381 testapp_print("input search filter key value : ");
1382 result_from_scanf = scanf("%s", search_key_value_string);
1383 search_filter.search_filter_key_value.string_type_key_value = search_key_value_string;
1386 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_BEFORE :
1387 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_ON :
1388 case EMAIL_SEARCH_FILTER_TYPE_SENT_DATE_SINCE :
1389 testapp_print("input search filter key value (format = YYYYMMDDHHMMSS) : ");
1390 result_from_scanf = scanf("%s", search_key_value_string);
1391 /* TODO : write codes for converting string to time */
1392 /* search_filter.search_filter_key_value.time_type_key_value = search_key_value_string; */
1395 testapp_print("Invalid filter type [%d]", search_filter_type);
1399 if( (err_code = email_search_mail_on_server(account_id, mailbox_id, &search_filter,1, &handle)) != EMAIL_ERROR_NONE) {
1400 testapp_print("email_search_mail_on_server failed [%d]", err_code);
1403 testapp_print(" >>> testapp_test_search_mail_on_server : END \n");
1407 static gboolean testapp_test_add_mail_to_search_result_box()
1412 int attachment_count = 0;
1413 int err = EMAIL_ERROR_NONE;
1414 int result_from_scanf = 0;
1415 char arg[50] = { 0 , };
1416 char *body_file_path = MAIL_TEMP_BODY;
1417 email_mailbox_t *mailbox_data = NULL;
1418 email_mail_data_t *test_mail_data = NULL;
1419 email_attachment_data_t *attachment_data = NULL;
1420 email_meeting_request_t *meeting_req = NULL;
1421 FILE *body_file = NULL;
1423 testapp_print("\n > Enter account id : ");
1424 result_from_scanf = scanf("%d", &account_id);
1426 email_get_mailbox_by_mailbox_type(account_id, EMAIL_MAILBOX_TYPE_SEARCH_RESULT, &mailbox_data);
1428 test_mail_data = malloc(sizeof(email_mail_data_t));
1429 memset(test_mail_data, 0x00, sizeof(email_mail_data_t));
1431 testapp_print("\n From EAS? [0/1]> ");
1432 result_from_scanf = scanf("%d", &from_eas);
1434 test_mail_data->account_id = account_id;
1435 test_mail_data->save_status = 1;
1436 test_mail_data->body_download_status = 1;
1437 test_mail_data->flags_seen_field = 1;
1438 test_mail_data->file_path_plain = strdup(body_file_path);
1439 test_mail_data->mailbox_id = mailbox_data->mailbox_id;
1440 test_mail_data->mailbox_type = mailbox_data->mailbox_type;
1441 test_mail_data->full_address_from = strdup("<test1@test.com>");
1442 test_mail_data->full_address_to = strdup("<test2@test.com>");
1443 test_mail_data->full_address_cc = strdup("<test3@test.com>");
1444 test_mail_data->full_address_bcc = strdup("<test4@test.com>");
1445 test_mail_data->subject = strdup("Into search result mailbox");
1447 body_file = fopen(body_file_path, "w");
1449 for(i = 0; i < 500; i++)
1450 fprintf(body_file, "X2 X2 X2 X2 X2 X2 X2");
1454 testapp_print(" > Attach file? [0/1] : ");
1455 result_from_scanf = scanf("%d",&attachment_count);
1457 if ( attachment_count ) {
1458 memset(arg, 0x00, 50);
1459 testapp_print("\n > Enter attachment name : ");
1460 result_from_scanf = scanf("%s", arg);
1462 attachment_data = malloc(sizeof(email_attachment_data_t));
1464 attachment_data->attachment_name = strdup(arg);
1466 memset(arg, 0x00, 50);
1467 testapp_print("\n > Enter attachment absolute path : ");
1468 result_from_scanf = scanf("%s",arg);
1470 attachment_data->attachment_path = strdup(arg);
1471 attachment_data->save_status = 1;
1472 test_mail_data->attachment_count = attachment_count;
1475 testapp_print("\n > Meeting Request? [0: no, 1: yes (request from server), 2: yes (response from local)]");
1476 result_from_scanf = scanf("%d", &(test_mail_data->meeting_request_status));
1478 if ( test_mail_data->meeting_request_status == 1
1479 || test_mail_data->meeting_request_status == 2 ) {
1480 time_t current_time;
1481 /* dummy data for meeting request */
1482 meeting_req = malloc(sizeof(email_meeting_request_t));
1483 memset(meeting_req, 0x00, sizeof(email_meeting_request_t));
1485 meeting_req->meeting_response = 1;
1486 current_time = time(NULL);
1487 gmtime_r(¤t_time, &(meeting_req->start_time));
1488 gmtime_r(¤t_time, &(meeting_req->end_time));
1489 meeting_req->location = malloc(strlen("Seoul") + 1);
1490 memset(meeting_req->location, 0x00, strlen("Seoul") + 1);
1491 strcpy(meeting_req->location, "Seoul");
1492 strcpy(meeting_req->global_object_id, "abcdef12345");
1494 meeting_req->time_zone.offset_from_GMT = 9;
1495 strcpy(meeting_req->time_zone.standard_name, "STANDARD_NAME");
1496 gmtime_r(¤t_time, &(meeting_req->time_zone.standard_time_start_date));
1497 meeting_req->time_zone.standard_bias = 3;
1499 strcpy(meeting_req->time_zone.daylight_name, "DAYLIGHT_NAME");
1500 gmtime_r(¤t_time, &(meeting_req->time_zone.daylight_time_start_date));
1501 meeting_req->time_zone.daylight_bias = 7;
1505 if((err = email_add_mail(test_mail_data, attachment_data, attachment_count, meeting_req, from_eas)) != EMAIL_ERROR_NONE)
1506 testapp_print("email_add_mail failed. [%d]\n", err);
1508 testapp_print("email_add_mail success.\n");
1510 testapp_print("saved mail id = [%d]\n", test_mail_data->mail_id);
1513 email_free_attachment_data(&attachment_data, attachment_count);
1516 email_free_meeting_request(&meeting_req, 1);
1518 email_free_mail_data(&test_mail_data, 1);
1519 email_free_mailbox(&mailbox_data, 1);
1524 static gboolean testapp_test_email_load_eml_file()
1526 email_mail_data_t *mail_data = NULL;
1527 email_attachment_data_t *mail_attachment_data = NULL;
1529 int attachment_count = 0;
1530 int err = EMAIL_ERROR_NONE;
1531 int result_from_scanf = 0;
1532 char eml_file_path[255] = {0, };
1534 testapp_print("Input eml file path : ");
1535 result_from_scanf = scanf("%s", eml_file_path);
1537 if ((err = email_open_eml_file(eml_file_path, &mail_data, &mail_attachment_data, &attachment_count)) != EMAIL_ERROR_NONE)
1539 testapp_print("email_open_eml_file failed : [%d]\n", err);
1543 testapp_print("load success\n");
1544 testapp_print("Return-Path: %s\n", mail_data->full_address_return);
1545 testapp_print("To: %s\n", mail_data->full_address_to);
1546 testapp_print("Subject: %s\n", mail_data->subject);
1547 testapp_print("From: %s\n", mail_data->full_address_from);
1548 testapp_print("Reply-To: %s\n", mail_data->full_address_reply);
1549 testapp_print("Sender: %s\n", mail_data->email_address_sender);
1550 testapp_print("Message-ID: %s\n", mail_data->message_id);
1551 testapp_print("attachment_count: %d\n", mail_data->attachment_count);
1552 testapp_print("inline content count : %d\n", mail_data->inline_content_count);
1554 for (i = 0;i < mail_data->attachment_count ; i++) {
1555 testapp_print("attachment_id: %d\n", mail_attachment_data[i].attachment_id);
1556 testapp_print("inline_attachment_status: %d\n", mail_attachment_data[i].inline_content_status);
1557 testapp_print("attachment_name: %s\n", mail_attachment_data[i].attachment_name);
1558 testapp_print("attachment_path: %s\n", mail_attachment_data[i].attachment_path);
1559 testapp_print("mailbox_id: %d\n", mail_attachment_data[i].mailbox_id);
1562 testapp_print("Success : Open eml file\n");
1564 if ((err = email_delete_eml_data(mail_data)) != EMAIL_ERROR_NONE) {
1565 testapp_print("email_delete_eml_data failed : [%d]\n", err);
1569 testapp_print("Success : email_delete_eml_data\n");
1572 email_free_mail_data(&mail_data, 1);
1574 testapp_print("Success : email_free_mail_data\n");
1576 if (mail_attachment_data)
1577 email_free_attachment_data(&mail_attachment_data, attachment_count);
1579 testapp_print("Success : email_free_attachment_data\n");
1585 /* internal functions */
1586 static gboolean testapp_test_interpret_command (int menu_number)
1588 gboolean go_to_loop = TRUE;
1590 switch (menu_number) {
1592 testapp_test_get_mails();
1595 testapp_test_mail_send(NULL);
1598 testapp_test_get_mail_list();
1601 testapp_test_add_attachment();
1604 testapp_test_set_deleted_flag();
1607 testapp_test_expunge_mails_deleted_flagged();
1610 testapp_test_count();
1613 testapp_test_delete();
1616 testapp_test_download_body();
1619 testapp_test_download_attachment();
1622 testapp_test_delete_all();
1625 testapp_test_move();
1628 testapp_test_retry_send();
1631 testapp_test_move_all_mails_to_mailbox();
1634 testapp_test_get_totaldiskusage();
1637 testapp_test_address_format_check_test();
1640 testapp_test_get_max_mail_count();
1643 testapp_test_db_test();
1646 testapp_test_send_cancel();
1649 testapp_test_cancel_download_body();
1652 testapp_test_get_mail_list_for_thread_view();
1655 testapp_test_test_get_thread_information();
1658 testapp_test_get_mail_list_ex();
1661 testapp_test_get_address_info_list();
1664 testapp_test_set_flags_field();
1667 testapp_test_add_mail(NULL);
1670 testapp_test_update_mail();
1673 testapp_test_search_mail_on_server();
1676 testapp_test_add_mail_to_search_result_box();
1679 testapp_test_email_load_eml_file();
1691 void testapp_mail_main()
1693 gboolean go_to_loop = TRUE;
1694 int menu_number = 0;
1695 int result_from_scanf = 0;
1697 while (go_to_loop) {
1698 testapp_show_menu(EMAIL_MAIL_MENU);
1699 testapp_show_prompt(EMAIL_MAIL_MENU);
1701 result_from_scanf = scanf("%d", &menu_number);
1703 go_to_loop = testapp_test_interpret_command (menu_number);