#include "testapp-utility.h"
#include "testapp-mailbox.h"
+static gboolean testapp_print_mailbox_list(email_mailbox_t *input_mailbox_list, int input_count)
+{
+ int i;
+ char time_string[40] = { 0, };
+
+
+
+ testapp_print("There are %d mailboxes\n", input_count);
+
+ testapp_print("============================================================================\n");
+ testapp_print("id a_id name\t\t\t alias\t\t unread\t total\t total_on_ server\tmailbox_type\t last_sync_time\n");
+ testapp_print("============================================================================\n");
+ if ( input_count == 0 ) {
+ testapp_print("No mailbox is matched\n");
+ }
+ else {
+ for(i=0;i<input_count;i++) {
+ strftime(time_string, 40, "%Y-%m-%d %H:%M:%S", localtime(&(input_mailbox_list[i].last_sync_time)));
+ testapp_print("[%2d]", input_mailbox_list[i].mailbox_id);
+ testapp_print(" %2d [%2d]\t[%-12s] ", input_mailbox_list[i].account_id, input_mailbox_list[i].mailbox_id, input_mailbox_list[i].alias);
+ testapp_print(" %3d\t %3d\t %3d\t %3d\t %s\n"
+ , input_mailbox_list[i].unread_count
+ , input_mailbox_list[i].total_mail_count_on_local
+ , input_mailbox_list[i].total_mail_count_on_server
+ , input_mailbox_list[i].mailbox_type
+ , time_string);
+ }
+ }
+ testapp_print("============================================================================\n");
+
+ return FALSE;
+}
+
static gboolean testapp_test_add_mailbox()
{
- emf_mailbox_t mbox;
+ email_mailbox_t mailbox;
int account_id,mailbox_type = 0;
int local_yn = 0;
char arg[500];
int ret;
unsigned handle;
+ int result_from_scanf = 0;
memset(arg, 0x00, 500);
testapp_print("\n> Enter mailbox name: ");
- scanf("%s",arg);
- mbox.name = strdup(arg);
+ result_from_scanf = scanf("%s",arg);
+ mailbox.mailbox_name = strdup(arg);
memset(arg, 0x00, 500);
testapp_print("> Enter mailbox alias name: ");
- scanf("%s",arg);
- mbox.alias = strdup(arg);
+ result_from_scanf = scanf("%s",arg);
+ mailbox.alias = strdup(arg);
testapp_print("> Enter account id: ");
- scanf("%d", &account_id);
- mbox.account_id = account_id;
+ result_from_scanf = scanf("%d", &account_id);
+ mailbox.account_id = account_id;
testapp_print("> Enter local_yn (1/0): ");
- scanf("%d", &local_yn);
- mbox.local= local_yn;
+ result_from_scanf = scanf("%d", &local_yn);
+ mailbox.local= local_yn;
testapp_print("> Enter mailbox type: ");
- scanf("%d", &mailbox_type);
- mbox.mailbox_type= mailbox_type;
+ result_from_scanf = scanf("%d", &mailbox_type);
+ mailbox.mailbox_type= mailbox_type;
- ret = email_add_mailbox(&mbox, local_yn?0:1, &handle);
+ ret = email_add_mailbox(&mailbox, local_yn?0:1, &handle);
if (ret < 0) {
testapp_print("\n email_add_mailbox failed");
}
else {
- testapp_print("\n email_add_mailbox succeed : handle[%d]\n", handle);
+ testapp_print("\n email_add_mailbox succeed : handle[%d], mailbox_id [%d]\n", handle, mailbox.mailbox_id);
}
return FALSE;
static gboolean testapp_test_delete_mailbox()
{
-
- emf_mailbox_t mbox;
- int account_id;
- int local_yn = 0;
- char arg[500];
+ int mailbox_id = 0;
+ int on_server = 0;
int ret;
unsigned handle;
+ int result_from_scanf = 0;
- memset(arg, 0x00, 500);
- testapp_print("\n> Enter mailbox name:");
- scanf("%s",arg);
- mbox.name = strdup(arg);
+ testapp_print("\n> Enter mailbox id:");
+ result_from_scanf = scanf("%d", &mailbox_id);
- testapp_print("> Enter account id: ");
- scanf("%d", &account_id);
- mbox.account_id = account_id;
-
- testapp_print("> Enter local_yn (1/0): ");
- scanf("%d", &local_yn);
+ testapp_print("> Enter on_server (1/0): ");
+ result_from_scanf = scanf("%d", &on_server);
- ret = email_delete_mailbox(&mbox, local_yn?0:1, &handle);
+ ret = email_delete_mailbox(mailbox_id, on_server, &handle);
if ( ret < 0) {
testapp_print("\n email_delete_mailbox failed");
}
-static gboolean testapp_test_update_mailbox()
+static gboolean testapp_test_rename_mailbox()
{
- testapp_print ("testapp_test_update_mailbox - support ONLY updating mailbox type\n");
- emf_mailbox_t *old_mailbox_name = NULL;
- emf_mailbox_t *new_mbox = NULL;
- int account_id,mailbox_type = 0;
- char arg[500];
+ testapp_print ("testapp_test_rename_mailbox\n");
+ int mailbox_id;
+ char mailbox_name[500] = { 0, };
+ char mailbox_alias[500] = { 0, };
int err;
-
- memset(arg, 0x00, 500);
+ int result_from_scanf = 0;
+ unsigned handle = 0;
- testapp_print("> Enter account id: ");
- scanf("%d", &account_id);
+ testapp_print("> Enter mailbox id: ");
+ result_from_scanf = scanf("%d", &mailbox_id);
- testapp_print("\n> Enter mailbox name: ");
- scanf("%s", arg);
-
- testapp_print("> Enter mailbox type: ");
- scanf("%d", &mailbox_type);
+ testapp_print("> Enter new mailbox name: ");
+ result_from_scanf = scanf("%s", mailbox_name);
+
+ testapp_print("> Enter new mailbox name: ");
+ result_from_scanf = scanf("%s", mailbox_alias);
- /* Get old mailbox information from db */
- if ( (err = email_get_mailbox_by_name(account_id, arg, &old_mailbox_name)) < 0 ) {
- testapp_print("\n email_get_mailbox_by_name failed[%d]\n", err);
- }
- else {
- testapp_print("\n email_get_mailbox_by_name succeed\n");
- }
-
- /* copy old maibox to new mailbox */
- if ( (err = email_get_mailbox_by_name(account_id, arg, &new_mbox)) < 0 ) {
- testapp_print("\n email_get_mailbox_by_name failed[%d]\n", err);
- }
- else {
- testapp_print("\n email_get_mailbox_by_name succeed\n");
- }
-
- /* set new value of new mailbox */
- new_mbox->mailbox_type= mailbox_type;
- if ( (err = email_update_mailbox(old_mailbox_name, new_mbox)) < 0) {
- testapp_print("\n email_update_mailbox failed[%d]\n", err);
+ if ( (err = email_rename_mailbox(mailbox_id, mailbox_name, mailbox_alias, true, &handle)) < 0) {
+ testapp_print("\n email_rename_mailbox failed[%d]\n", err);
}
else {
- testapp_print("\n email_update_mailbox succeed\n");
+ testapp_print("\n email_rename_mailbox succeed\n");
}
- email_free_mailbox(&old_mailbox_name, 1);
- email_free_mailbox(&new_mbox, 1);
-
return FALSE;
}
{
int account_id = 0;
unsigned handle = 0;
+ int result_from_scanf = 0;
testapp_print("> Enter account id: ");
- scanf("%d", &account_id);
+ result_from_scanf = scanf("%d", &account_id);
- if( email_get_imap_mailbox_list(account_id, "", &handle) < 0)
- testapp_print("email_get_imap_mailbox_list failed");
+ if( email_sync_imap_mailbox_list(account_id, &handle) < 0)
+ testapp_print("email_sync_imap_mailbox_list failed");
return FALSE;
}
-static gboolean testapp_test_get_child_mailbox_list ()
+static gboolean testapp_test_get_mailbox_by_type ()
{
- int account_id =0;
- int count = 0;
- int i = 0, err_code = EMF_ERROR_NONE;
- emf_mailbox_t *mailbox_list=NULL;
- char parent_mailbox[100], *parent_mailbox_pointer = NULL;
-
-
- memset(parent_mailbox,0x00,sizeof(parent_mailbox));
+ int account_id =0;
+ int err_code = EMAIL_ERROR_NONE;
+ int result_from_scanf = 0;
+ email_mailbox_t *mailbox =NULL;
+ email_mailbox_type_e mailbox_type =0;
testapp_print("\n > Enter account id: ");
- scanf("%d", &account_id);
-
- testapp_print("\n > Enter parent mailbox name to fetch child list: ");
- scanf("%s", parent_mailbox);
-
-
+ result_from_scanf = scanf("%d", &account_id);
- if(strcmp(parent_mailbox, "0") != 0) {
- testapp_print("\ninput : %s\n", parent_mailbox);
- parent_mailbox_pointer = parent_mailbox;
- }
+ testapp_print("\n > Enter mailbox_type: ");
+ result_from_scanf = scanf("%d", (int*)&mailbox_type);
- if( (err_code = email_get_child_mailbox_list(account_id,parent_mailbox_pointer, &mailbox_list, &count)) < 0) {
- testapp_print(" email_get_child_mailbox_list error : %d\n",err_code);
+ if( (err_code = email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox)) < 0) {
+ testapp_print(" email_get_mailbox_by_mailbox_type error : %d\n",err_code);
return false ;
}
- testapp_print("There are %d mailboxes\n", count);
-
- testapp_print("============================================================================\n");
- testapp_print("number\taccount_id\t name\t alias\t local_yn\t unread\t mailbox_type\thas_archived_mails\n");
- testapp_print("============================================================================\n");
- if(count == 0) {
- testapp_print("No mailbox is matched\n");
- }
- else {
- for(i=0;i<count;i++)
- {
- testapp_print("[%d] - ", i);
- testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
- testapp_print(" %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count,mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
- }
- }
- testapp_print("============================================================================\n");
+ testapp_print_mailbox_list(mailbox, 1);
- email_free_mailbox(&mailbox_list, count);
+ email_free_mailbox(&mailbox, 1);
return FALSE;
}
-static gboolean testapp_test_get_mailbox_by_type ()
+static gboolean testapp_test_set_mailbox_type()
{
+ int mailbox_id = 0;
+ int mailbox_type = 0;
+ int err_code = EMAIL_ERROR_NONE;
+ int result_from_scanf = 0;
- int account_id =0;
- int i = 0, err_code = EMF_ERROR_NONE;
- emf_mailbox_t *mailbox =NULL;
- emf_mailbox_type_e mailbox_type =0;
-
- testapp_print("\n > Enter account id: ");
- scanf("%d", &account_id);
+ testapp_print("\n > Enter mailbox id : ");
+ result_from_scanf = scanf("%d", &mailbox_id);
- testapp_print("\n > Enter mailbox_type: ");
- scanf("%d", (int*)&mailbox_type);
+ testapp_print("\n > Enter mailbox type : ");
+ result_from_scanf = scanf("%d", &mailbox_type);
- if( (err_code = email_get_mailbox_by_mailbox_type(account_id,mailbox_type,&mailbox)) < 0) {
- testapp_print(" email_get_mailbox_by_mailbox_type error : %d\n",err_code);
- return false ;
+ if( (err_code = email_set_mailbox_type(mailbox_id, mailbox_type) ) != EMAIL_ERROR_NONE) {
+ testapp_print("\nemail_set_mailbox_type error : %d\n", err_code);
}
- testapp_print("============================================================================\n");
- testapp_print("number\taccount_id\t name\t alias\t local_yn\t unread\t mailbox_type\thas_archived_mails\n");
- testapp_print("============================================================================\n");
-
- testapp_print("[%d] - ", i);
- testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox->account_id, mailbox->name, mailbox->alias);
- testapp_print(" %d\t %d\t %d\n", mailbox->local, mailbox->unread_count,mailbox->mailbox_type, mailbox->has_archived_mails);
-
- testapp_print("============================================================================\n");
-
- email_free_mailbox(&mailbox, 1);
return FALSE;
}
static gboolean testapp_test_set_mail_slot_size ()
{
-
- int account_id = 0, mail_slot_size = 0;
- int err_code = EMF_ERROR_NONE;
- char arg[500];
- char *mailbox_name = NULL;
+ int account_id = 0;
+ int mailbox_id = 0;
+ int mail_slot_size = 0;
+ int err_code = EMAIL_ERROR_NONE;
+ int result_from_scanf = 0;
testapp_print("\n > Enter account id (0: All account): ");
- scanf("%d", &account_id);
+ result_from_scanf = scanf("%d", &account_id);
- memset(arg, 0x00, 500);
- testapp_print("\n> Enter mailbox name (0 : All mailboxes):");
- scanf("%s",arg);
- if (strcmp(arg, "0") != 0 ) {
- mailbox_name = arg;
- }
+ testapp_print("\n> Enter mailbox id (0 : All mailboxes):");
+ result_from_scanf = scanf("%d", &mailbox_id);
testapp_print("\n > Enter mailbox slot size: ");
- scanf("%d", &mail_slot_size);
+ result_from_scanf = scanf("%d", &mail_slot_size);
- if( (err_code = email_set_mail_slot_size(account_id, mailbox_name, mail_slot_size) ) < 0) {
+ if( (err_code = email_set_mail_slot_size(account_id, mailbox_id, mail_slot_size) ) < 0) {
testapp_print(" testapp_test_set_mail_slot_size error : %d\n", err_code);
return false ;
}
static gboolean testapp_test_get_mailbox_list ()
{
-
+ int result_from_scanf = 0;
int account_id =0;
int mailbox_sync_type;
int count = 0;
- int i = 0, error_code = EMF_ERROR_NONE;
- emf_mailbox_t *mailbox_list=NULL;
+ int error_code = EMAIL_ERROR_NONE;
+ email_mailbox_t *mailbox_list=NULL;
testapp_print("\n > Enter account id: ");
- scanf("%d", &account_id);
+ result_from_scanf = scanf("%d", &account_id);
testapp_print("\n > Enter mailbox_sync_type\n[-1 :for all mailboxes, 0 : for mailboxes from server, 1 : local mailboxes\n : ");
- scanf("%d", &mailbox_sync_type);
+ result_from_scanf = scanf("%d", &mailbox_sync_type);
if((error_code = email_get_mailbox_list(account_id, mailbox_sync_type, &mailbox_list, &count)) < 0) {
testapp_print(" email_get_mailbox_list error %d\n", error_code);
return false ;
}
- testapp_print("There are %d mailboxes\n", count);
+ testapp_print_mailbox_list(mailbox_list, count);
- testapp_print("============================================================================\n");
- testapp_print("number\taccount_id\t name\t\t alias\t local_yn\t unread\tmailbox_type\t has_archived_mails\n");
- testapp_print("============================================================================\n");
- if ( count == 0 ) {
- testapp_print("No mailbox is matched\n");
- }
- else {
- for(i=0;i<count;i++) {
- testapp_print("[%d] - ", i);
- testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
- testapp_print(" %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count,mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
- }
- }
- testapp_print("============================================================================\n");
- /* EmfMailboxFree(emf_mailbox_t** mailbox_list, int count, int* err_code) */
+ email_free_mailbox(&mailbox_list, count);
if((error_code = email_get_mailbox_list_ex(account_id, mailbox_sync_type, 1, &mailbox_list, &count)) < 0) {
testapp_print(" email_get_mailbox_list_ex error %d\n", error_code);
return false ;
}
- testapp_print("There are %d mailboxes\n", count);
-
- testapp_print("============================================================================\n");
- testapp_print("number\taccount_id\t name\t\t alias\t local_yn\t unread\t total\t total_on_ server\tmailbox_type\t has_archived_mails\n");
- testapp_print("============================================================================\n");
- if ( count == 0 ) {
- testapp_print("No mailbox is matched\n");
- }
- else {
- for(i=0;i<count;i++) {
- testapp_print("[%d] - ", i);
- testapp_print(" %2d\t [%-15s]\t[%-15s]\t", mailbox_list[i].account_id, mailbox_list[i].name, mailbox_list[i].alias);
- testapp_print(" %d\t %d\t %d\t %d\t %d\t %d\n", mailbox_list[i].local, mailbox_list[i].unread_count, mailbox_list[i].total_mail_count_on_local, mailbox_list[i].total_mail_count_on_server, mailbox_list[i].mailbox_type, mailbox_list[i].has_archived_mails);
- }
- }
- testapp_print("============================================================================\n");
- testapp_print("Start to free\n");
+ testapp_print_mailbox_list(mailbox_list, count);
email_free_mailbox(&mailbox_list, count);
return FALSE;
static gboolean testapp_test_sync_mailbox()
{
- emf_mailbox_t mbox;
+ int result_from_scanf = 0;
int account_id = 0;
- char arg[50];
unsigned handle = 0;
- testapp_print("\n > Enter Account id (0: for all account) : ");
- scanf("%d",&account_id);
-
- memset(arg, 0x00, 50);
- testapp_print("\n > Enter Mailbox name (ALL: for all mailboxes) : ");
- scanf("%s",arg);
-
- memset(&mbox, 0x00, sizeof(emf_mailbox_t));
+ int mailbox_id = 0;
- mbox.account_id = account_id;
+ testapp_print("\n > Enter Account id (0: for all account) : ");
+ result_from_scanf = scanf("%d",&account_id);
- if(strcmp("ALL", arg) == 0)
- mbox.name = NULL;
- else
- mbox.name = strdup(arg);
+ testapp_print("\n > Enter Mailbox id (0: for all mailboxes) : ");
+ result_from_scanf = scanf("%d",&mailbox_id);
if(account_id == ALL_ACCOUNT) {
if(email_sync_header_for_all_account(&handle) < 0)
testapp_print("\n email_sync_header_for_all_account success. Handle[%d]\n", handle);
}
else {
- if(email_sync_header(&mbox,&handle) < 0)
+ if(email_sync_header(account_id, mailbox_id, &handle) < 0)
testapp_print("\n email_sync_header failed\n");
else
testapp_print("\n email_sync_header success. Handle[%d]\n", handle);
return FALSE;
}
+static gboolean testapp_test_stamp_sync_time()
+{
+ int result_from_scanf;
+ int input_mailbox_id = 0;
+
+ testapp_print("\n > Enter Mailbox id : ");
+ result_from_scanf = scanf("%d",&input_mailbox_id);
+
+ email_stamp_sync_time_of_mailbox(input_mailbox_id);
+
+ return FALSE;
+}
+
static gboolean testapp_test_interpret_command (int menu_number)
{
gboolean go_to_loop = TRUE;
break;
case 2:
- testapp_test_delete_mailbox ();
+ testapp_test_delete_mailbox();
break;
case 3:
- testapp_test_update_mailbox ();
+ testapp_test_rename_mailbox();
break;
case 4:
testapp_test_get_imap_mailbox_list();
break;
- case 6:
- testapp_test_get_child_mailbox_list();
- break;
-
case 7:
testapp_test_get_mailbox_by_type();
- break;
+ break;
case 8:
- testapp_test_set_mail_slot_size();
+ testapp_test_set_mailbox_type();
break;
case 9:
+ testapp_test_set_mail_slot_size();
+ break;
+
+ case 10:
testapp_test_get_mailbox_list ();
break;
- case 10:
+ case 11:
testapp_test_sync_mailbox();
break;
+ case 12:
+ testapp_test_stamp_sync_time();
+ break;
+
case 0:
go_to_loop = FALSE;
break;
return go_to_loop;
}
-void emf_test_mailbox_main()
+void email_test_mailbox_main()
{
gboolean go_to_loop = TRUE;
int menu_number = 0;
+ int result_from_scanf = 0;
while (go_to_loop) {
- testapp_show_menu (EMF_MAILBOX_MENU);
- testapp_show_prompt (EMF_MAILBOX_MENU);
+ testapp_show_menu (EMAIL_MAILBOX_MENU);
+ testapp_show_prompt (EMAIL_MAILBOX_MENU);
- scanf ("%d", &menu_number);
+ result_from_scanf = scanf("%d", &menu_number);
go_to_loop = testapp_test_interpret_command (menu_number);
}